HttpWebRequest work differently in debug/release

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi everyone. I hope it is the right category.
Ive a problem with a code because it work differently if I test it in Visual Studio either I test it on my site.
i am trying to do an autologin on an external web site. If I test it from VS, I am correctly redirected on the external site. From my site i obtain i am redirected to "http://www.MySite.com/cgi-bin/wbc_login/...."!!!!!

The code is the following:


<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; private <span style="color:Blue; void MioMetodo(String username, String password)
{
CookieContainer Cookies = <span style="color:Blue; new CookieContainer();

Cookie langCookie = <span style="color:Blue; new Cookie(<span style="color:#A31515; "pk_lang", <span style="color:#A31515; ""italiano"", <span style="color:#A31515; "/");
langCookie.Domain = <span style="color:#A31515; "xxx.yy";
Cookie loginCookie = <span style="color:Blue; new Cookie(<span style="color:#A31515; "wc_loginoslimit", <span style="color:#A31515; """ + username + <span style="color:#A31515; """, <span style="color:#A31515; "/");
loginCookie.Domain = <span style="color:#A31515; "xxx.yy";
Cookie passwordCookie = <span style="color:Blue; new Cookie(<span style="color:#A31515; "wc_passwordoslimit", <span style="color:#A31515; """ + password + <span style="color:#A31515; """, <span style="color:#A31515; "/");
passwordCookie.Domain = <span style="color:#A31515; "xxx.yy";

Cookies.Add(langCookie);
Cookies.Add(loginCookie);
Cookies.Add(passwordCookie);

UTF8Encoding encoding = <span style="color:Blue; new UTF8Encoding();
String postData = <span style="color:#A31515; "wc_login=" + username + <span style="color:#A31515; "&wc_password=" + password + <span style="color:#A31515; "&limit=0&Avanti=Avanti";
Byte[] data = encoding.GetBytes(postData);

HttpWebRequest myHttpWebRequest = WebRequest.Create(<span style="color:#A31515; "http://xxx.yy/cgi-bin/wbc_login") <span style="color:Blue; as HttpWebRequest;
myHttpWebRequest.Method = <span style="color:#A31515; "POST";
myHttpWebRequest.Referer = <span style="color:#A31515; "http://xxx.yy/cgi-bin/wbc_login";

myHttpWebRequest.Headers.Add(HttpRequestHeader.AcceptCharset, <span style="color:#A31515; "ISO-8859-1,utf-8;q=0.7,*;q=0.3");
myHttpWebRequest.Headers.Add(HttpRequestHeader.AcceptEncoding, <span style="color:#A31515; "gzip,deflate,sdch");
myHttpWebRequest.Headers.Add(HttpRequestHeader.AcceptLanguage, <span style="color:#A31515; "it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4");
myHttpWebRequest.Headers.Add(HttpRequestHeader.CacheControl, <span style="color:#A31515; "max-age=0");
myHttpWebRequest.ContentType = <span style="color:#A31515; "application/x-www-form-urlencoded";
myHttpWebRequest.CookieContainer = Cookies;
myHttpWebRequest.ContentLength = data.Length;

Stream newStream = myHttpWebRequest.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();

HttpWebResponse myHttpWebResponse = myHttpWebRequest.GetResponse() <span style="color:Blue; as HttpWebResponse;
StreamReader streamRead =<span style="color:Blue; new StreamReader(myHttpWebResponse.GetResponseStream());
Response.Write(streamRead.ReadToEnd());

streamRead.Close();
myHttpWebResponse.Close();
}
[/code]
Thanx in advance<br/>
<br/>


View the full article
 
Back
Top