Link to home
Create AccountLog in
Avatar of Jeff Fillegar
Jeff FillegarFlag for United States of America

asked on

c# httpclient - send authentication with request

Hello Experts,

I need to pass username and password with my httpclient post.  How can I do that?

string username = "user";
string password="pw";

 string theCall = string.Format(qryString, "xml", "dbo", m_QryName);

 using (var client = new HttpClient(BaseUri))
{

                    // Serialize object to send to the service
                    HttpContent theContent = HttpContentExtensions.Create(param.ToXElement<string>());
                    
                    // Send request and get response
                    using (HttpResponseMessage response = client.Post(theCall, theContent))
                    {
                     
                    }
}

Open in new window

SOLUTION
Avatar of Dale Burrell
Dale Burrell
Flag of New Zealand image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
ASKER CERTIFIED SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.