HttpWebRequest.Create()不起作用 [英] HttpWebRequest.Create() not working

查看:363
本文介绍了HttpWebRequest.Create()不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试形成如下所示的请求:

 WebRequest request = HttpWebRequest.Create(  http://finance.yahoo.com/d/quotes.csv?s=%5EGSPC&f=sl1nc6



它在调试环境中运行良好,但在部署后抛出错误。好像请求即将为空。

解决方案

让我们看看。父类是 WebRequest ,派生类显然是 HttpWebRequest 。现在,你明白什么是编译时什么是运行时类?您还需要知道 WebRequest.Create 是一个静态方法,它可以返回不同运行时类的实例,具体取决于URI scheme 。是否足以理解该怎么做?



如果这还不够,请查看此MSDN帮助页面中的代码示例,但请仔细查看: http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx [ ^ ]。



看到差异?阅读备注部分中的 WebRequest.Create 。顺便说一句,这种静态方法有时被称为工厂方法



-SA

Hi,i am trying to form a request like the below:

WebRequest request = HttpWebRequest.Create("http://finance.yahoo.com/d/quotes.csv?s=%5EGSPC&f=sl1nc6")


It works good in the debugging environment but throwing error after deployment. Seems like the request is coming null.

解决方案

Let's see. The parent class is WebRequest and derived class is, apparently HttpWebRequest. Now, do you understand what is compile-time and what is runtime class? You also need to know that WebRequest.Create is a static method which can return instanced of different runtime classed, depending on URI scheme. Is it enough to understand what to do?

If this is not enough, look at the code sample in this MSDN help page, but look thoroughly: http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx[^].

See the difference? Read about WebRequest.Create in the "Remarks" section. By the way, such static methods are sometimes called "factory methods".

—SA


这篇关于HttpWebRequest.Create()不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆