HttpWebRequest with cookie proxy settings

Here is my code:

var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://localhost/jsonrpc.cgi"); httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = "POST"; using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { string json = "someParameters"; streamWriter.Write(json); } var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var responseText = streamReader.ReadToEnd(); } string Bugzilla_logincookie= httpResponse.Headers.ToString(); Bugzilla_logincookie= Bugzilla_logincookie.Substring(plsWork .IndexOf("logincookie") + 12); Bugzilla_logincookie= Bugzilla_logincookie.Substring(0, plsWork .IndexOf(";")); CookieContainer cc = new CookieContainer(); cc.SetCookies(new Uri("http://localhost"), Bugzilla_logincookie); var httpWebRequest2 = (HttpWebRequest)WebRequest.Create("http://localhost/jsonrpc.cgi"); httpWebRequest2.ContentType = "application/json"; httpWebRequest2.Method = "POST"; httpWebRequest2.Proxy.Credentials = new NetworkCredential("username", "password"); httpWebRequest2.CookieContainer = cc; using (var streamWriter2 = new StreamWriter(httpWebRequest2.GetRequestStream())) { string json = "someParametersForJsonCall"; streamWriter2.Write(json); } var httpResponse2 = (HttpWebResponse)httpWebRequest2.GetResponse(); using (var streamReader2 = new StreamReader(httpResponse2.GetResponseStream())) { var responseText = streamReader2.ReadToEnd(); } 

I have a problem using a proxy. What I'm trying to do is use a proxy for http://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/User.html to call the login method and then save the files answer cookie and send them with every session call. I get this error:

 "You must log in before using this part of Bugzilla." 

What am I mistakenly using?

+4
source share

Source: https://habr.com/ru/post/1397401/


All Articles