开发者

Cookies are required to use this site. HttpWebRequest/HttpWebResponse Cookies

开发者 https://www.devze.com 2022-12-09 10:31 出处:网络
I am using the following code to make a HttpWebRequest and render the XML from the response stream. ` HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);

I am using the following code to make a HttpWebRequest and render the XML from the response stream.

` HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);

req.Accept = "/";

req.Headers.Add("UA-CPU", "x86");

req.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; MS-RTC LM 8)";

req.CookieContainer = new CookieContainer();

using (HttpWebResponse resp = (HttpWebResponse)req.GetResponse())

{

using (StreamReader reader = new StreamReader(resp.GetResponseStream()))

{

  sb.Append(reader.ReadToEnd());

}

}`

It was working fine on my local server and test server but on UAT server, i am getting the response as 'Cookies are required to use this site'. I don't understand why this is happenning. If I browse to the URL directly, valid XML is getting rendered but it doesn't work if use the above co开发者_开发技巧de. Can anyone help, please?


It sounds like the sever is expecting a cookie that you aren't sending. After you browse to the URL in the browser, type this in the location bar to see the cookies: javascript:alert(document.cookie);

0

精彩评论

暂无评论...
验证码 换一张
取 消