奇怪的是,当我在浏览器上运行这个URL时,我得到了的正确回应。
是不是webrequest需要返回与浏览器相同的值?
下面的代码返回错误的请求
// Create a request for the URL.
WebRequest request = WebRequest.Create(
"http://someUrl/api/v5/basicAuth");
// Get the response.
WebResponse response = request.GetResponse();
// Display the status.
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
// Display the content.
Console.WriteLine(responseFromServer);
// Clean up the streams and the response.
reader.Close();
response.Close();
使用Web客户端使用相同的结果,也试过。
任何想法如何获得与浏览器相同的正确响应?
2014-07-06
baaroz