session - How can I make an HTTPWebRequest to an ASP.NET web service and appear that I'm logged into that domain? -
I have a web service on which I can only hit if I am logged in to the web site Ongoing I need to test service remotely. Therefore, I have written some code to create a fake session which is logged on the site in another browser. Then I made an HTTP web request and I am trying to set the cookie in which the user has ASP.NET session ID. But the web service does not detect that the web request is a logged user or session. Why do I need to provide a web service to understand that this is a valid session?
// Each reading job is used on byte [] buf = new byte [8192]; Cookie Container myContainer = New Cookie Container (); String sessionID = session id; MyContainer.Add (new cookie ("ASP.NET_SessionId", session ID, "/", WebsiteUrl)); // Prepare web page 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. Cook Container = myContainer; Stream s = request.GetRequestStream (); String soap = ""; Soaprequest + = "& lt ;? Xml version = \" 1.0 \ "encoding = \" utf-8 \ "? & Gt;"; Soaprequest + = "& lt; Soap 12: 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-invelope \ "& gt;"; Soaprequest + = "& lt; Soap 12: Body & gt;"; Soaprequest + = "doneScreenScore xmlns = \" http: //detectent.net/ \ "& gt;"; Soaprequest + = "& lt; Input 1" string "; Soaprequest + = "& lt; Input 2> string "; Soaprequest + = "& lt; Input 3" string "; Soaprequest + = "& lt; Input4" string "; Soaprequest + = "& lt; / doneScreenScore>"; Soaprequest + = "& lt; / Soap 12: Body & gt;"; Soaprequest + = "& lt; / Soap 12: Envelope"; S.Write (System.Text.Encoding.ASCII.GetBytes (soaprequest), 0, soaprequest.Length); S.Close (); // Request HttpWebResponse response = (HttpWebResponse) execute the request. GETResponse (); // We will read the data via the response stream stream stream = response. GETResponseStream (); String Response FrameWebService = RedspansSstream (Restream);
I think you can do something with credentials ... I I am doing a webservice for ...
rpt.Credentials = New System.Net.NetworkCredential (username, password, domain);
Comments
Post a Comment