HttpWebRequest 类型“GET”返回错误400

发布于 2024-12-03 17:51:58 字数 493 浏览 1 评论 0原文

它似乎只发生在一台机器上,其他机器上都没有发生。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

万劫不复 2024-12-10 17:51:58

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.

小耗子 2024-12-10 17:51:58

(不是真正的答案,但太大了,无法评论)

对于它的价值,我运行了以下 Python 代码(太懒了,无法启动 C# :),它工作得很好:

import httplib
conn = httplib.HTTPSConnection('connect.zystemsgo.com')
conn.request('GET', '/auto/')
resp = conn.getresponse()
data = resp.read()
print data           # expected ouput, just like visiting in a browser
print resp.status    # 200

你确定你向我们展示了实际的 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:

import httplib
conn = httplib.HTTPSConnection('connect.zystemsgo.com')
conn.request('GET', '/auto/')
resp = conn.getresponse()
data = resp.read()
print data           # expected ouput, just like visiting in a browser
print resp.status    # 200

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...

情场扛把子 2024-12-10 17:51:58

这是一个错误的请求错误。请求中没有参数吗?
您能否发布响应消息,它会告诉您出了什么问题。

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.

停滞 2024-12-10 17:51:58

我在上面的评论中提供的代码有效。
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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文