从 C# 应用程序调用 Google Chart API 时出现问题
我想在 Job 或 Winforms 应用程序中生成 QR 码。
我的 api 调用很简单:
http://chart.apis.google.com/chart?cht=qr&chld=L|0&chs=80x80&chl=http%3a%2f%2futip.it.%2ft%2f1833
当我从浏览器调用它时就很好了。
当我使用以下代码调用它时,出现超时错误:
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
request.Timeout = 5000;
request.ReadWriteTimeout = 5000;
request.ContentType = "image/png";
HttpWebResponse imgresponse = (HttpWebResponse)request.GetResponse();
System.Drawing.Image img = System.Drawing.Image.FromStream(imgresponse.GetResponseStream());
当我打开 Fiddler 来调试请求时,它可以工作。我假设我需要在请求上设置一些标头。我尝试了一些但没有成功..
I want to generate a QR Code in a Job or Winforms app.
My api call is straightforward:
http://chart.apis.google.com/chart?cht=qr&chld=L|0&chs=80x80&chl=http%3a%2f%2futip.it.%2ft%2f1833
When I call it from the browser its fine.
When I call it using the following code, I get a timeout error:
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
request.Timeout = 5000;
request.ReadWriteTimeout = 5000;
request.ContentType = "image/png";
HttpWebResponse imgresponse = (HttpWebResponse)request.GetResponse();
System.Drawing.Image img = System.Drawing.Image.FromStream(imgresponse.GetResponseStream());
When I turn on Fiddler to debug the request, it works. I assume that I need to set some header on the request. I've tried a few but no success..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不太明白为什么,但使用这段代码是有效的:
Don't really understand why, but using this code works: