Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I make an HTTPWebRequest to an ASP.NET web service and appear that I'm logged into that domain?
    text
    copied!<p>I have a web service that I can only hit if I'm logged into the website that the web service is on. I need to test the service remotely. So I've written some code to create a fake session that is logged into the site in another browser. Then I made the HTTP Web Request and I'm attempting to set a cookie that contains the ASP.NET session ID of that logged in user. But the web service doesn't detect that the web request is a logged in user or session. What do I need to give the web service to convince it this is a valid session?</p> <pre><code>// used on each read operation byte[] buf = new byte[8192]; CookieContainer myContainer = new CookieContainer(); string sessionID = SessionID; myContainer.Add(new Cookie("ASP.NET_SessionId", sessionID, "/", WebsiteUrl)); // prepare the web page we will be asking for HttpWebRequest request = (HttpWebRequest) WebRequest.Create(CreateWebserviceUrl("doneScreenScore")); request.ContentType = "text/xml; charset=utf-8"; request.Method = "POST"; request.Accept = "text/xml"; request.Headers.Add("SOAPAction", "http://detectent.net/doneScreenScore"); request.CookieContainer = myContainer; Stream s = request.GetRequestStream(); string soaprequest = ""; soaprequest += "&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;"; soaprequest += "&lt;soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\"&gt;"; soaprequest += " &lt;soap12:Body&gt;"; soaprequest += " &lt;doneScreenScore xmlns=\"http://detectent.net/\"&gt;"; soaprequest += " &lt;input1&gt;string&lt;/input1&gt;"; soaprequest += "&lt;input2&gt;string&lt;/input2&gt;"; soaprequest += "&lt;input3&gt;string&lt;/input3&gt;"; soaprequest += "&lt;input4&gt;string&lt;/input4&gt;"; soaprequest += "&lt;/doneScreenScore&gt;"; soaprequest += "&lt;/soap12:Body&gt;"; soaprequest += "&lt;/soap12:Envelope&gt;"; s.Write(System.Text.Encoding.ASCII.GetBytes(soaprequest), 0, soaprequest.Length); s.Close(); // execute the request HttpWebResponse response = (HttpWebResponse) request.GetResponse(); // we will read data via the response stream Stream resStream = response.GetResponseStream(); string responseFromWebServiceCall = ReadResponseStream(resStream); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload