i am making a request to a 3rd party RESTful service using Microsoft's HttpClient
. It works flawlessly (and is very easy to implement) except for this one instance. Here is a breakdown from the provider as to what is occurring during the error:
"The way the POST to the group resource works is that when it completes, it does a HTTP 302 redirect to the group instance resource. What appears to be happening is that your HTTP Client is sending the proper authentication information to the POST, which creates the group resource, but when it handles the GET for the HTTP 302 request, it is not sending the right credentials and is getting a 401 response. Can you check your client library and make sure its sending HTTP auth parameters properly on redirects?"
Here is my POST code:
HttpClient http = new HttpClient(BASE_URL);
http.TransportSettings.Credentials = new NetworkCredential(ACCOUNT_SID,
ACCOUNT_TOKEN);
HttpResponseMessage httpResponse = http.Post(groupUri, "application/xml",
HttpContent.Create(xml.ToString()));
result = httpResponse.Content.ReadAsString();
Which brings me to my question; how do I get the authentication parameters to send on this GET redirect using the HttpClient
class?
I had a similar problem and at the end I added a form with a WebBrowser control. Whithout calling
form.Show()
I can tell him to navigate to an URL, click buttons and all. Here is the class that controls that form:And here is the code for the form (some extra code is needed to disable the clicking sound).
And the Microsoft Html Object COM Library should be added if the source code is needed.