Last post Dec 15, 2010 10:58 AM by Annee975
Dec 06, 2010 10:20 AM|Annee975|LINK
Using a Windows application I am sending a web request to a web page and getting the response back using the following code
HttpWebRequest oRequest1 = (HttpWebRequest)WebRequest.Create(url);
oRequest1.ContentType = "text/xml";
using (Stream stream = oRequest1.GetRequestStream())
stream.Write(fileBytes1, 0, fileBytes2.Length); //fileBytes1 - contains the data of first request
HttpWebResponse Response1 = (HttpWebResponse)oRequest1.GetResponse();
->The above code works fine
But I need to enhance the code to accomodate following additional scenario
->Send another request to the same web app and
->get the response back
The first request sent contains the credentials to access the web application
the second request sent doesn't have credentials, it must use the credentials of first request.
I am using the same (following) code for the second request too. I get an error saying that it's looking for credentials
HttpWebRequest oRequest2 = (HttpWebRequest)WebRequest.Create(url);
oRequest2.ContentType = "text/xml";
using (Stream stream = oRequest2.GetRequestStream())
stream.Write(fileBytes2, 0, fileBytes2.Length);
HttpWebResponse Response2 = (HttpWebResponse)oRequest2.GetResponse();
So how do I accomplish this?
Should I be sending the second request using same session or same connection?
Can anyone please provide sample code for this?Appreciate any help/suggestions too. Thanks!
Dec 08, 2010 06:15 PM|rstrahl|LINK
Try using the same instance of the WebRequest you create. It should maintain an HTTP session...
If that doesn't work you have to capture the headers and resend them on the second request. Authentication is tracked with session cookies embedded in the HTTP header. You can capture that header when receiving the result from the server, then send that
same header back on the second request.
There's an example of how you can capture Cookies (which is similar to headers altogether) in this article (towards the middle of the document):
Hope this helps,
+++ Rick ---
Dec 15, 2010 10:58 AM|Annee975|LINK
Thanks for the response.
My problem was solved since the third party changed the requirement by modifying the xml format of the second request which now has credentials on the second request xml too..