HttpWebRequest 类型“GET”返回错误400
它似乎只发生在一台机器上,其他机器上都没有发生。
HttpWebRequest myRequest =(HttpWebRequest)WebRequest.Create("https://connect.zystemsgo.com/auto/");
myRequest.Method = "GET";
SetCertificatePolicy();
Application.DoEvents();
WebResponse myResponse = myRequest.GetResponse();
StreamReader sr = new StreamReader(myResponse.GetResponseStream(),System.Text.Encoding.UTF8);
string result = sr.ReadToEnd();
我尝试搜索其他400请求错误,但不清楚。我该如何调试这个?
It seems to be occurring only one machine and none of the other machines.
HttpWebRequest myRequest =(HttpWebRequest)WebRequest.Create("https://connect.zystemsgo.com/auto/");
myRequest.Method = "GET";
SetCertificatePolicy();
Application.DoEvents();
WebResponse myResponse = myRequest.GetResponse();
StreamReader sr = new StreamReader(myResponse.GetResponseStream(),System.Text.Encoding.UTF8);
string result = sr.ReadToEnd();
I tried searching other 400 request errors, but it is not clear. How do I go about debugging this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
HTTP 错误 400 表示错误请求。这是服务器返回的。
通常,当我调试 HTTP 请求时,我使用 Fiddler 来监视请求和响应并找出这是怎么回事。它永远不会失败。
HTTP Error 400 means Bad Request. This is being returned by the server.
Usually, when I'm debugging HTTP requests, I use Fiddler to monitor the requests and responses and find out what's going on. It never fails.
(不是真正的答案,但太大了,无法评论)
对于它的价值,我运行了以下 Python 代码(太懒了,无法启动 C# :),它工作得很好:
你确定你向我们展示了实际的 URL失败了,或者您的代码是一个更通用的示例?
也许该机器上没有安装服务器证书?在这种情况下我不会想到 HTTP 400,但这是迄今为止我能想到的唯一的事情......
(Not really an answer, but too big for comment)
For what it's worth, I ran the following Python code (too lazy to spin up C# :), and it worked fine:
Are you sure you are showing us the URL that is actually failing, or is your code a more general example?
Perhaps the server certificate is not installed on that machine? I wouldn't expect a HTTP 400 in that case, but it's the only thing I can think of so far...
这是一个错误的请求错误。请求中没有参数吗?
您能否发布响应消息,它会告诉您出了什么问题。
it is a bad request error .Are there no parameters in the request?
Can you post the response message,it will give some idea of what is going wrong.
我在上面的评论中提供的代码有效。
WebClient webClient = new WebClient();
webClient.DownloadFile("您的文件的完整网址", @"c:\myfile.txt");
您需要拥有在您选择的目录中写入的权限。
如果需要,您也可以尝试使用异步下载。我不明白为什么它不能在某台机器上运行。
The code that i supplied in the comment above works.
WebClient webClient = new WebClient();
webClient.DownloadFile("Your complete url for the file", @"c:\myfile.txt");
you need to have permission to write in the directory of your choice.
You could also try and use the async download if you want.I am not getting why it would not work on a certain machine.