远程服务器返回错误:(403)禁止在C#中

时间:2015-11-14 04:55:46

标签: c# web-scraping

远程服务器返回错误:(403)Forbidden.below是我的代码..我收到错误 - “远程服务器返回错误:(403)禁止。”..:

        HttpWebRequest request = WebRequest.Create("https://in.xxxx.com/extranet/inventory/submitroomrates/") as HttpWebRequest;
            request.Method = "POST";
            request.Accept = "*/*";
            request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
            request.ContentLength = postdata.Length;
            request.CookieContainer = cookie;
            request.UseDefaultCredentials = true;
            //request.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36";
            request.Referer = "https://in.xxx.com/extranet/";
            request.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
            request.Headers[HttpRequestHeader.Cookie] = sessioncookie;

            //request.Headers.Add(HttpRequestHeader.Cookie, sessioncookie);

            byte[] byteArray = Encoding.UTF8.GetBytes(postdata);
            request.ContentLength = byteArray.Length;

            Stream dataStream = request.GetRequestStream();
            dataStream.Write(byteArray, 0, byteArray.Length);
            dataStream.Close();
            StreamReader response = new StreamReader(request.GetResponse().GetResponseStream()); ===>got error
            var res = response.ReadToEnd();

0 个答案:

没有答案