vb.net - HttpWebRequest POST and Cookies -
Hi trying to create an application that posts data to a Joomla login page but the only thing that I I do not have cookies enabled.
Function as NewGrid.CookieContainer Dim enc as encoding = Encoding.GetEncoding (1252) Bit by default as GetPage (String as ByVal Url) () = Somewhat slow PostData as string = "" if InStr (url, "?") & Lt; & Gt; 0 then PostData = Url.Substring (InStr (Url, "?") URL = Change (URL, PostData, URL = URL.Remind ("?" C) Data = NF Gatebytes (PostData) End and Dim Req Like System .Net.HttpWebRequest = CType (Net.WebRequest.Create (Url), Net.HttpWebRequest) req.AllowAutoRedirect = False req.ContentType = "Application / X-www-Form-URLXode" req.Method = "POST" if no data So the data is not. Lang & gt; 0 then req.ContentLength = Data.Length dim as stream = req.GetRequestStream () newStream.Write (data, 0, data. Length) newStream.Flush () newStream.Close () End if end req.CookieContainer = CookieJar DM res Net as Pat.HTTP Web Response = CTP (Reak Gate Response (), .NET. HTTP Webbashings) as Deem ResponseStream IO.StreamReader = New IO.StreamReader (Response Gateresonsstream (), Enf) Dame HTML String ResponseStream.Close () Return HTML and Function
How should I do?
View this sample: < Code>. >
Cookie Container Cookies = New Cookie Container (); HttpWebRequest postRequest = (HttpWebRequest) WebRequest.Create (site); PostRequest.CookieContainer = Cookies; // This postRequest.Method = "Post" note; PostRequest.ContentType = "application / x-www-form-urlencoded"; (Stream stream = writerequest.getrequesteststream ()) using {stream.Write (buffer, 0, buffer length); }
Comments
Post a Comment