I am trying to login to a site using HttpWebRequest
Post. It works perfectly fine. But when i use a proxy to login it wont work. The connection Timeouts, and if i remove the part:
request.Host="abc.com
";
It works again fine with proxy , but doing the above will forbid me from login as the site needs that info . How can i over come this any suggestions?
CODE"
HttpWebRequest httpWReq =
(HttpWebRequest)WebRequest.Create(url);
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = post;
byte[] data = encoding.GetBytes(postData);
string proxy = "58.20.127.26:3128";
/////byte[] data = GetBytes(postData);
WebProxy myProxy = new WebProxy(proxy);
httpWReq.Proxy = myProxy;
httpWReq.Method = "POST";
httpWReq.Accept = "text/html, application/xhtml+xml, */*";
httpWReq.Referer = refferr;
httpWReq.CookieContainer = yumCookies;
httpWReq.ContentType = "application/x-www-form-urlencoded";
httpWReq.UserAgent = "xxxxxxxxxxx";
httpWReq.Host = "xxx.com";
httpWReq.Headers.Add("Accept-Language: en-US");
httpWReq.ContentLength = data.Length;
httpWReq.KeepAlive = true;
httpWReq.Headers.Add("Pragma: no-cache");
httpWReq.AllowAutoRedirect = true;
httpWReq.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
using (Stream stream = httpWReq.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
Stream responseStream = response.GetResponseStream();
StreamReader myStreamReader = new StreamReader(responseStream);
responseString = myStreamReader.ReadToEnd();
if (response.Cookies.Count > 0)
{
foreach (Cookie ck in response.Cookies)
{
yumCookies.Add(ck);
}
}
}
response.Close();
response = null;
response = null;