首页 新闻 赞助 找找看

学习编程问题,怎么觉得微软官网上有错

0
悬赏园豆:5 [已解决问题] 解决于 2012-04-04 10:11

今天学习要用到这个类HttpWebRequest,在msdn上查找  在这个网页上http://msdn.microsoft.com/zh-cn/library/system.net.httpwebrequest_members(v=vs.90).aspx

但是我就觉得很郁闷,我在我的vs里建立了HttpWebRequest类就是点不出GetResponse方法。

然后我又到这个网页http://msdn.microsoft.com/zh-cn/library/system.net.httpwebrequest.getresponse(v=vs.90).aspx复制粘贴下面的代码都有错编译不过去。

HttpWebRequest request = (HttpWebRequest)WebRequest.Create (args[0]);

// Set some reasonable limits on resources used by this request
request.MaximumAutomaticRedirections = 4;
request.MaximumResponseHeadersLength = 4;
// Set credentials to use for this request.
request.Credentials = CredentialCache.DefaultCredentials;
HttpWebResponse response = (HttpWebResponse)request.GetResponse ();

Console.WriteLine ("Content length is {0}", response.ContentLength);
Console.WriteLine ("Content type is {0}", response.ContentType);

// Get the stream associated with the response.
Stream receiveStream = response.GetResponseStream ();

// Pipes the stream to a higher level stream reader with the required encoding format.
StreamReader readStream = new StreamReader (receiveStream, Encoding.UTF8);

Console.WriteLine ("Response stream received.");
Console.WriteLine (readStream.ReadToEnd ());
response.Close ();
readStream.Close ();



这是怎么回事?求解?

learnWindowsPhone的主页 learnWindowsPhone | 初学一级 | 园豆:38
提问于:2012-04-02 12:58
< >
分享
最佳答案
1

说了这么大堆你漏掉了最重要的一点就是开发环境,windows phone开发中不支持同步的操作,所有网络操作必须是异步的。你只能用BeginGetResponse。继续去看例子吧。

收获园豆:5
水牛刀刀 | 大侠五级 |园豆:6350 | 2012-04-03 13:29

哦,明白了,关键是windows phone开发中不支持同步的操作。

是不是还会有别的什么原因,我现在认为就是这个原因,希望有人再来关注下这个问题,明天或后天我再结贴。

learnWindowsPhone | 园豆:38 (初学一级) | 2012-04-03 14:14
其他回答(2)
-1

.net 版本?

.NET Framework

.NET Compact Framework

受以下版本支持:3.5、2.0、1.0

子夜一梦 | 园豆:213 (菜鸟二级) | 2012-04-02 13:56

我前面就试了,不是版本的问题。

支持(0) 反对(0) learnWindowsPhone | 园豆:38 (初学一级) | 2012-04-02 14:33
1

没错,只是你没会用,HttpWebRequest request = (HttpWebRequest)WebRequest.Create (args[0]);你传入的命令行参数非法,长度为0.你可以用 Environment.GetCommandLineArgs获取,解决的办法很多

微软提供的都是是这种模式:手动打开  运行-->cmd --->转到程序所在的路径(当然你可以直接拉入) +Test(类名)+传入的命令行参数

解决方法:1。在最前面传一句类似args = new string[1] {"http://baidu.com" };就行了

具体可以看我的文章:http://www.cnblogs.com/rohelm/archive/2012/03/14/2395254.html

Halower | 园豆:1723 (小虾三级) | 2012-04-02 19:04

不是那样的,我前面有些问题没有说清楚。

刚才我试着建立了别的项目比如控件台应用程序,Web项目程序比如写入下面的一段的代码

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://baidu.com");
void Method()
{
request.GetResponse();
}

引用命名空间后都是好的。

但我之前说的那个程序是在windows phone项目中的,新建一个类或者windows phone类库加入上面段代码怎么弄都是错。我想这是windows phone项目和别的和不同之处吧,不能用这个类其中的一些方面,是这样理解的吗,请高手作答!
这是不是windows phone用的.net framework和别的其它项目比如Web项目用的.net framework不同的原故?

支持(0) 反对(0) learnWindowsPhone | 园豆:38 (初学一级) | 2012-04-02 22:16

我又在vs里面转到定义看windows phone项目中和Web项目中看HttpWebRequest这个类的定义,发现也是不同的,下面先是在windows phone项目中HttpWebRequest这个类的定义的代码

#region Assembly System.Net.dll, v2.0.50727
// C:\Program Files\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0\Profile\WindowsPhone71\System.Net.dll
#endregion

using System;
using System.IO;

namespace System.Net
{
// Summary:
// Provides an HTTP-specific implementation of the System.Net.WebRequest class.
public class HttpWebRequest : WebRequest
{
// Summary:
// Initializes a new instance of the System.Net.HttpWebRequest class.
protected HttpWebRequest();

// Summary:
// Gets or sets the value of the Accept HTTP header.
//
// Returns:
// The value of the Accept HTTP header. The default value is null.
public string Accept { get; set; }
//
// Summary:
// Gets or sets a value that indicates whether the request should follow redirection
// responses.
//
// Returns:
// true if the request should automatically follow redirection responses from
// the Internet resource; otherwise false. The default is true.
//
// Exceptions:
// System.NotImplementedException:
// This property is not implemented.
public virtual bool AllowAutoRedirect { get; set; }
//
// Summary:
// When overridden in a descendant class, gets or sets a value that indicates
// whether to buffer the data read from the Internet resource.
//
// Returns:
// true to enable buffering of the data received from the Internet resource;
// false to disable buffering. The default is true.
//
// Exceptions:
// System.NotImplementedException:
// This property is not implemented.
public virtual bool AllowReadStreamBuffering { get; set; }
//
// Summary:
// Gets or sets the value of the Content-type HTTP header.
//
// Returns:
// The value of the Content-type HTTP header. The default value is null.
public override string ContentType { get; set; }
//
// Summary:
// Specifies the collection of System.Net.CookieCollection objects associated
// with the HTTP request.
//
// Returns:
// A System.Net.CookieContainer that contains a collection of System.Net.CookieCollection
// objects associated with the HTTP request.
//
// Exceptions:
// System.NotImplementedException:
// This property is not implemented.
public virtual CookieContainer CookieContainer { get; set; }
//
// Summary:
// Gets or sets authentication information for the request.
//
// Returns:
// An System.Net.ICredentials that contains the authentication credentials associated
// with the request. The default is null.
public override ICredentials Credentials { get; set; }
//
// Summary:
// Gets a value that indicates whether a response has been received from an
// Internet resource.
//
// Returns:
// true if a response has been received; otherwise, false.
//
// Exceptions:
// System.NotImplementedException:
// This property is not implemented.
public virtual bool HaveResponse { get; }
//
// Summary:
// Specifies a collection of the name/value pairs that make up the HTTP headers.
//
// Returns:
// A System.Net.WebHeaderCollection that contains the name/value pairs that
// make up the headers for the HTTP request.
//
// Exceptions:
// System.InvalidOperationException:
// The request has been started by calling the System.Net.HttpWebRequest.BeginGetRequestStream(System.AsyncCallback,System.Object)
// or System.Net.HttpWebRequest.BeginGetResponse(System.AsyncCallback,System.Object)
// method.
public override WebHeaderCollection Headers { get; set; }
//
// Summary:
// Gets or sets the method for the request.
//
// Returns:
// The request method to use to contact the Internet resource. The default value
// is GET.
//
// Exceptions:
// System.ArgumentException:
// No method is supplied.-or- The method string contains invalid characters.
//
// System.NotImplementedException:
// This property is not implemented.
//
// System.NotSupportedException:
// The System.Net.HttpWebRequest.Method property is not GET or POST.
public override string Method { get; set; }
//
// Summary:
// Gets the original Uniform Resource Identifier (URI) of the request.
//
// Returns:
// A System.Uri that contains the URI of the Internet resource passed to the
// System.Net.WebRequest.Create(System.Uri) method.
//
// Exceptions:
// System.NotImplementedException:
// This property is not implemented.
public override Uri RequestUri { get; }
//
// Summary:
// Gets a value that indicates whether the System.Net.HttpWebRequest.CookieContainer
// property is supported by the System.Net.HttpWebRequest instance.
//
// Returns:
// true if the System.Net.HttpWebRequest.CookieContainer property is supported
// by the System.Net.HttpWebRequest instance; otherwise, false.
public virtual bool SupportsCookieContainer { get; }
//
// Summary:
// Gets or sets the value of the User-agent HTTP header.
//
// Returns:
// The value of the User-agent HTTP header. The default value is null.Note:The
// value for this property is stored in System.Net.WebHeaderCollection. If WebHeaderCollection
// is set, the property value is lost.
public string UserAgent { get; set; }

// Summary:
// Cancels a request to an Internet resource.
//
// Exceptions:
// System.NotImplementedException:
// This method is not implemented.
public override void Abort();
//
// Summary:
// Begins an asynchronous request for a System.IO.Stream object to use to write
// data.
//
// Parameters:
// callback:
// The System.AsyncCallback delegate.
//
// state:
// The state object for this request.
//
// Returns:
// An System.IAsyncResult that references the asynchronous request.
//
// Exceptions:
// System.Net.ProtocolViolationException:
// The System.Net.HttpWebRequest.Method property is GET-or- The System.Net.WebRequest.ContentLength
// property was set to a value that does not match the size of the provided
// request body.
//
// System.InvalidOperationException:
// The stream is being used by a previous call to System.Net.HttpWebRequest.BeginGetRequestStream(System.AsyncCallback,System.Object)-or-
// The thread pool is running out of threads.
//
// System.NotImplementedException:
// This method is not implemented.
//
// System.NotSupportedException:
// The request cache validator indicated that the response for this request
// can be served from the cache; however, requests that write data must not
// use the cache. This exception can occur if you are using a custom cache validator
// that is incorrectly implemented.
//
// System.Net.WebException:
// System.Net.HttpWebRequest.Abort() was previously called.
//
// System.ObjectDisposedException:
// In a .NET Framework application, a request stream with zero content length
// was not obtained and closed correctly.
public override IAsyncResult BeginGetRequestStream(AsyncCallback callback, object state);
//
// Summary:
// Begins an asynchronous request to an Internet resource.
//
// Parameters:
// callback:
// The System.AsyncCallback delegate
//
// state:
// The state object for this request.
//
// Returns:
// An System.IAsyncResult that references the asynchronous request for a response.
//
// Exceptions:
// System.InvalidOperationException:
// The stream is already in use by a previous call to System.Net.HttpWebRequest.BeginGetResponse(System.AsyncCallback,System.Object)-or-
// The thread pool is running out of threads.
//
// System.NotImplementedException:
// This method is not implemented.
//
// System.NotSupportedException:
// The callback parameter is null.
//
// System.Net.ProtocolViolationException:
// System.Net.HttpWebRequest.Method is GET.
//
// System.Net.WebException:
// System.Net.HttpWebRequest.Abort() was previously called.
public override IAsyncResult BeginGetResponse(AsyncCallback callback, object state);
//
// Summary:
// Ends an asynchronous request for a System.IO.Stream object to use to write
// data.
//
// Parameters:
// asyncResult:
// The pending request for a stream.
//
// Returns:
// A System.IO.Stream to use to write request data.
//
// Exceptions:
// System.ArgumentNullException:
// asyncResult is null.
//
// System.IO.IOException:
// The request did not complete, and no stream is available.
//
// System.ArgumentException:
// asyncResult was not returned by the current instance from a call to System.Net.HttpWebRequest.BeginGetRequestStream(System.AsyncCallback,System.Object).
//
// System.InvalidOperationException:
// This method was called previously using asyncResult.
//
// System.NotImplementedException:
// This method is not implemented.
//
// System.Net.WebException:
// System.Net.HttpWebRequest.Abort() was previously called.-or- An error occurred
// while processing the request.
public override Stream EndGetRequestStream(IAsyncResult asyncResult);
//
// Summary:
// Ends an asynchronous request to an Internet resource.
//
// Parameters:
// asyncResult:
// The pending request for a response.
//
// Returns:
// A System.Net.WebResponse that contains the response from the Internet resource.
//
// Exceptions:
// System.ArgumentNullException:
// asyncResult is null.
//
// System.InvalidOperationException:
// This method was called previously using asyncResult.
//
// System.NotImplementedException:
// This method is not implemented.
//
// System.Net.WebException:
// System.Net.HttpWebRequest.Abort() was previously called.-or- An error occurred
// while processing the request.
//
// System.ArgumentException:
// asyncResult was not returned by the current instance from a call to System.Net.HttpWebRequest.BeginGetResponse(System.AsyncCallback,System.Object).
public override WebResponse EndGetResponse(IAsyncResult asyncResult);
}
}

下面的是在我新建立的一个解决方案的控制台应用程序那个类的定义代码

#region 程序集 System.dll, v4.0.30319
// C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.dll
#endregion

using System;
using System.IO;
using System.Net.Cache;
using System.Runtime;
using System.Runtime.Serialization;
using System.Security.Cryptography.X509Certificates;

namespace System.Net
{
// 摘要:
// 提供 System.Net.WebRequest 类的 HTTP 特定的实现。
[Serializable]
public class HttpWebRequest : WebRequest, ISerializable
{
// 摘要:
// 从 System.Runtime.Serialization.SerializationInfo 和 System.Runtime.Serialization.StreamingContext
// 类的指定实例初始化 System.Net.HttpWebRequest 类的新实例。
//
// 参数:
// serializationInfo:
// System.Runtime.Serialization.SerializationInfo 对象,包含序列化新 System.Net.HttpWebRequest
// 对象所需的信息。
//
// streamingContext:
// System.Runtime.Serialization.StreamingContext 对象,包含与新 System.Net.HttpWebRequest
// 对象关联的序列化流的源和目标。
[Obsolete("Serialization is obsoleted for this type. http://go.microsoft.com/fwlink/?linkid=14202")]
protected HttpWebRequest(SerializationInfo serializationInfo, StreamingContext streamingContext);

// 摘要:
// 获取或设置 Accept HTTP 标头的值。
//
// 返回结果:
// Accept HTTP 标头的值。默认值为 null。
public string Accept { get; set; }
//
// 摘要:
// 获取实际响应请求的 Internet 资源的统一资源标识符 (URI)。
//
// 返回结果:
// System.Uri,标识实际响应请求的 Internet 资源。默认值是供 System.Net.WebRequest.Create(System.String)
// 方法用来初始化请求的 URI。
public Uri Address { get; }
//
// 摘要:
// 获取或设置一个值,该值指示请求是否应跟随重定向响应。
//
// 返回结果:
// 如果请求应自动跟随 Internet 资源的重定向响应,则为 true,否则为 false。默认值为 true。
public bool AllowAutoRedirect { get; set; }
//
// 摘要:
// 获取或设置一个值,该值指示是否对发送到 Internet 资源的数据进行缓冲处理。
//
// 返回结果:
// true 允许对发送到 Internet 资源的数据进行缓冲处理,false 禁用缓冲处理。默认值为 true。
public bool AllowWriteStreamBuffering { get; set; }
//
// 摘要:
// 获取或设置所使用的解压缩类型。
//
// 返回结果:
// 一个 T:System.Net.DecompressionMethods 对象,该对象指示所使用的解压缩类型。
//
// 异常:
// System.InvalidOperationException:
// 对象的当前状态不允许设置此属性。
public DecompressionMethods AutomaticDecompression { get; set; }
//
// 摘要:
// 获取或设置与此请求关联的安全证书集合。
//
// 返回结果:
// System.Security.Cryptography.X509Certificates.X509CertificateCollection,包含与此请求关联的安全证书。
//
// 异常:
// System.ArgumentNullException:
// 为 Set 操作指定的值为 null。
public X509CertificateCollection ClientCertificates { get; set; }
//
// 摘要:
// 获取或设置 Connection HTTP 标头的值。
//
// 返回结果:
// Connection HTTP 标头的值。默认值为 null。
//
// 异常:
// System.ArgumentException:
// 将 System.Net.HttpWebRequest.Connection 的值设置为 Keep-alive 或 Close。
public string Connection { get; set; }
//
// 摘要:
// 获取或设置请求的连接组的名称。
//
// 返回结果:
// 该请求的连接组的名称。默认值为 null。
public override string ConnectionGroupName { get; set; }
//
// 摘要:
// 获取或设置 Content-lengthHTTP 标头。
//
// 返回结果:
// 要发送到 Internet 资源的数据的字节数。默认值为 -1,该值指示尚未设置该属性,并且没有要发送的请求数据。
//
// 异常:
// System.InvalidOperationException:
// 已通过调用 System.Net.HttpWebRequest.GetRequestStream()、System.Net.HttpWebRequest.BeginGetRequestStream(System.AsyncCallback,System.Object)、System.Net.HttpWebRequest.GetResponse()
// 或 System.Net.HttpWebRequest.BeginGetResponse(System.AsyncCallback,System.Object)
// 方法启动了该请求。
//
// System.ArgumentOutOfRangeException:
// 新的 System.Net.HttpWebRequest.ContentLength 值小于 0。
public override long ContentLength { get; set; }
//
// 摘要:
// 获取或设置 Content-typeHTTP 标头的值。
//
// 返回结果:
// Content-typeHTTP 标头的值。默认值为 null。
public override string ContentType { get; set; }
//
// 摘要:
// 获取或设置当从 Internet 资源接收到 HTTP 100 持续响应时调用的委托方法。
//
// 返回结果:
// 实现回调方法的委托,该方法在从 Internet 资源返回 HTTP 持续响应时执行。默认值为 null。
public HttpContinueDelegate ContinueDelegate { get; set; }
//
// 摘要:
// 获取或设置与此请求关联的 cookie。
//
// 返回结果:
// 包含与此请求关联的 Cookie 的 System.Net.CookieContainer。
public CookieContainer CookieContainer { get; set; }
//
// 摘要:
// 获取或设置请求的身份验证信息。
//
// 返回结果:
// 包含与该请求关联的身份验证凭据的 System.Net.ICredentials。默认值为 null。
public override ICredentials Credentials { get; set; }
//
// 摘要:
// 获取或设置要在 HTTP 请求中使用的 Date HTTP 标头值。
//
// 返回结果:
// HTTP 请求中的 Date 标头值。
public DateTime Date { get; set; }
//
// 摘要:
// 获取或设置此请求的默认缓存策略。
//
// 返回结果:
// 一个 System.Net.Cache.HttpRequestCachePolicy,它指定当没有其他策略适用时对此请求有效的缓存策略。
public static RequestCachePolicy DefaultCachePolicy { get; set; }
//
// 摘要:
// 获取或设置 HTTP 错误响应的默认最大长度。
//
// 返回结果:
// 一个整数,它表示 HTTP 错误响应的默认最大长度。
//
// 异常:
// System.ArgumentOutOfRangeException:
// 该值小于 0 并且不等于 -1。
public static int DefaultMaximumErrorResponseLength { get; set; }
//
// 摘要:
// 获取或设置 System.Net.HttpWebRequest.MaximumResponseHeadersLength 属性的默认值。
//
// 返回结果:
// 接收的响应标头的默认最大长度,以 KB(1024 字节)为单位。默认配置文件将此值设置为 64 KB。
//
// 异常:
// System.ArgumentOutOfRangeException:
// 该值不等于 -1 且小于 0。
public static int DefaultMaximumResponseHeadersLength { get; set; }
//
// 摘要:
// 获取或设置 ExpectHTTP 标头的值。
//
// 返回结果:
// ExpectHTTP 标头的内容。默认值为 null。Note此属性的值存储在 System.Net.WebHeaderCollection 中。如果设置了
// WebHeaderCollection,则该属性值将丢失。
//
// 异常:
// System.ArgumentException:
// Expect 被设置为一个包含“100-continue”(作为子字符串)的字符串。
public string Expect { get; set; }
//
// 摘要:
// 获取一个值,该值指示是否收到了来自 Internet 资源的响应。
//
// 返回结果:
// 如果接收到了响应,则为 true,否则为 false。
public bool HaveResponse { get; }
//
// 摘要:
// 指定构成 HTTP 标头的名称/值对的集合。
//
// 返回结果:
// 包含构成 HTTP 请求标头的名称/值对的 System.Net.WebHeaderCollection。
//
// 异常:
// System.InvalidOperationException:
// 已通过调用 System.Net.HttpWebRequest.GetRequestStream()、System.Net.HttpWebRequest.BeginGetRequestStream(System.AsyncCallback,System.Object)、System.Net.HttpWebRequest.GetResponse()
// 或 System.Net.HttpWebRequest.BeginGetResponse(System.AsyncCallback,System.Object)
// 方法启动了该请求。
public override WebHeaderCollection Headers { get; set; }
//
// 摘要:
// 获取或设置要在 HTTP 请求中独立于请求 URI 使用的 Host 标头值。
//
// 返回结果:
// HTTP 请求中的 Host 标头值。
//
// 异常:
// System.ArgumentNullException:
// 不能将主机标头设置为 null。
//
// System.ArgumentException:
// 不能将主机标头设置为无效值。
//
// System.InvalidOperationException:
// 在已经开始发送 System.Net.HttpWebRequest 之后,不能设置主机标头。
public string Host { get; set; }
//
// 摘要:
// 获取或设置 If-Modified-Since HTTP 标头的值。
//
// 返回结果:
// 包含 If-Modified-SinceHTTP 标头内容的 System.DateTime。默认值是当前日期和时间。
public DateTime IfModifiedSince { get; set; }
//
// 摘要:
// 获取或设置一个值,该值指示是否与 Internet 资源建立持久性连接。
//
// 返回结果:
// 如果对 Internet 资源的请求所包含的 Connection HTTP 标头带有 Keep-alive 这一值,则为 true;否则为 false。默认值为
// true。
public bool KeepAlive { get; set; }
//
// 摘要:
// 获取或设置请求将跟随的重定向的最大数目。
//
// 返回结果:
// 请求将跟随的重定向响应的最大数目。默认值为 50。
//
// 异常:
// System.ArgumentException:
// 该值被设置为 0 或更小。
public int MaximumAutomaticRedirections { get; set; }
//
// 摘要:
// 获取或设置响应标题允许的最大长度。
//
// 返回结果:
// 响应标题的长度,以 KB(1024 字节)为单位。
//
// 异常:
// System.InvalidOperationException:
// 该属性是在提交请求后设置的。
//
// System.ArgumentOutOfRangeException:
// 该值小于 0 并且不等于 -1。
public int MaximumResponseHeadersLength { get; set; }
//
// 摘要:
// 获取或设置请求的媒体类型。
//
// 返回结果:
// 请求的媒体类型。默认值为 null。
public string MediaType { get; set; }
//
// 摘要:
// 获取或设置请求的方法。
//
// 返回结果:
// 用于联系 Internet 资源的请求方法。默认值是 GET。
//
// 异常:
// System.ArgumentException:
// 未提供任何方法。- 或 -方法字符串包含无效字符。
public override string Method { get; set; }
//
// 摘要:
// 获取或设置一个值,该值指示是否通过管线将请求传输到 Internet 资源。
//
// 返回结果:
// 如果通过管线传输请求,则为 true,否则为 false。默认值为 true。
public bool Pipelined { get; set; }
//
// 摘要:
// 获取或设置一个值,该值指示是否随请求发送一个身份验证标头。
//
// 返回结果:
// true 表示在发生身份验证之后随请求一起发送 WWW-authenticate HTTP 标头;否则为 false。默认值为 false。
public override bool PreAuthenticate { get; set; }
//
// 摘要:
// 获取或设置用于请求的 HTTP 版本。
//
// 返回结果:
// 用于请求的 HTTP 版本。默认值为 System.Net.HttpVersion.Version11。
//
// 异常:
// System.ArgumentException:
// HTTP 版本被设置为除 1.0 或 1.1 以外的值。
public Version ProtocolVersion { get; set; }
//
// 摘要:
// 获取或设置请求的代理信息。
//
// 返回结果:
// 用于代理请求的 System.Net.IWebProxy 对象。默认值通过调用 System.Net.GlobalProxySelection.Select
// 属性设置。
//
// 异常:
// System.ArgumentNullException:
// System.Net.HttpWebRequest.Proxy 设置为 null。
//
// System.InvalidOperationException:
// 已通过调用 System.Net.HttpWebRequest.GetRequestStream()、System.Net.HttpWebRequest.BeginGetRequestStream(System.AsyncCallback,System.Object)、System.Net.HttpWebRequest.GetResponse()
// 或 System.Net.HttpWebRequest.BeginGetResponse(System.AsyncCallback,System.Object)
// 启动了该请求。
//
// System.Security.SecurityException:
// 调用方没有进行请求的操作的权限。
public override IWebProxy Proxy { get; set; }
//
// 摘要:
// 获取或设置写入或读取流时的超时(以毫秒为单位)。
//
// 返回结果:
// 在写入超时或读取超时之前的毫秒数。默认值为 300,000 毫秒(5 分钟)。
//
// 异常:
// System.InvalidOperationException:
// 已发送请求。
//
// System.ArgumentOutOfRangeException:
// 为 Set 操作指定的值小于等于零,并且不等于 System.Threading.Timeout.Infinite
public int ReadWriteTimeout { get; set; }
//
// 摘要:
// 获取或设置 RefererHTTP 标头的值。
//
// 返回结果:
// RefererHTTP 标头的值。默认值为 null。
public string Referer { get; set; }
//
// 摘要:
// 获取请求的原始统一资源标识符 (URI)。
//
// 返回结果:
// 一个 System.Uri,其中包含传递给 System.Net.WebRequest.Create(System.String) 方法的 Internet
// 资源的 URI。
public override Uri RequestUri { get; }
//
// 摘要:
// 获取或设置一个值,该值指示是否将数据分段发送到 Internet 资源。
//
// 返回结果:
// 如果为 true,则将数据分段发送到 Internet 资源;否则为 false。默认值为 false。
//
// 异常:
// System.InvalidOperationException:
// 已通过调用 System.Net.HttpWebRequest.GetRequestStream()、System.Net.HttpWebRequest.BeginGetRequestStream(System.AsyncCallback,System.Object)、System.Net.HttpWebRequest.GetResponse()
// 或 System.Net.HttpWebRequest.BeginGetResponse(System.AsyncCallback,System.Object)
// 方法启动了该请求。
public bool SendChunked { get; set; }
//
// 摘要:
// 获取用于请求的服务点。
//
// 返回结果:
// 表示与 Internet 资源的网络连接的 System.Net.ServicePoint。
public ServicePoint ServicePoint { get; }
//
// 摘要:
// 获取或设置 System.Net.HttpWebRequest.GetResponse() 和 System.Net.HttpWebRequest.GetRequestStream()
// 方法的超时值(以毫秒为单位)。
//
// 返回结果:
// 请求超时前等待的毫秒数。默认值是 100,000 毫秒(100 秒)。
//
// 异常:
// System.ArgumentOutOfRangeException:
// 指定的值小于零,并且不为 System.Threading.Timeout.Infinite。
public override int Timeout { get; set; }
//
// 摘要:
// 获取或设置 Transfer-encodingHTTP 标头的值。
//
// 返回结果:
// Transfer-encodingHTTP 标头的值。默认值为 null。
//
// 异常:
// System.InvalidOperationException:
// 当 System.Net.HttpWebRequest.SendChunked 为 false 时设置 System.Net.HttpWebRequest.TransferEncoding。
//
// System.ArgumentException:
// System.Net.HttpWebRequest.TransferEncoding 被设置为值“Chunked”。
public string TransferEncoding { get; set; }
//
// 摘要:
// 获取或设置一个值,该值指示是否允许经过高速 NTLM 身份验证的连接共享。
//
// 返回结果:
// true 表示使经过身份验证的连接保持打开状态;否则为 false。
public bool UnsafeAuthenticatedConnectionSharing { get; set; }
//
// 摘要:
// 获取或设置一个 System.Boolean 值,该值控制默认凭据是否随请求一起发送。
//
// 返回结果:
// 如果使用默认凭据,则为 true;否则为 false。默认值为 false。
//
// 异常:
// System.InvalidOperationException:
// 您尝试在该请求发送之后设置此属性。
public override bool UseDefaultCredentials { get; set; }
//
// 摘要:
// 获取或设置 User-agentHTTP 标头的值。
//
// 返回结果:
// User-agentHTTP 标头的值。默认值为 null。Note此属性的值存储在 System.Net.WebHeaderCollection
// 中。如果设置了 WebHeaderCollection,则该属性值将丢失。
public string UserAgent { get; set; }

// 摘要:
// 取消对 Internet 资源的请求。
[TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
public override void Abort();
//
// 摘要:
// 向请求添加从请求数据的开始处或结束处的特定范围的字节范围标头。
//
// 参数:
// range:
// 范围的开始点或结束点。
//
// 异常:
// System.ArgumentException:
// rangeSpecifier 无效。
//
// System.InvalidOperationException:
// 未能添加范围标头。
public void AddRange(int range);
//
// 摘要:
// 向请求添加从请求数据的开始处或结束处的特定范围的字节范围标头。
//
// 参数:
// range:
// 范围的开始点或结束点。
//
// 异常:
// System.ArgumentException:
// rangeSpecifier 无效。
//
// System.InvalidOperationException:
// 未能添加范围标头。
[TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
public void AddRange(long range);
//
// 摘要:
// 向请求添加指定范围的字节范围标头。
//
// 参数:
// from:
// 开始发送数据的位置。
//
// to:
// 停止发送数据的位置。
//
// 异常:
// System.ArgumentException:
// rangeSpecifier 无效。
//
// System.ArgumentOutOfRangeException:
// from大于to。- 或 -from 或 to 小于 0。
//
// System.InvalidOperationException:
// 未能添加范围标头。
public void AddRange(int from, int to);
//
// 摘要:
// 向请求添加指定范围的字节范围标头。
//
// 参数:
// from:
// 开始发送数据的位置。
//
// to:
// 停止发送数据的位置。
//
// 异常:
// System.ArgumentException:
// rangeSpecifier 无效。
//
// System.ArgumentOutOfRangeException:
// from大于to。- 或 -from 或 to 小于 0。
//
// System.InvalidOperationException:
// 未能添加范围标头。
[TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
public void AddRange(long from, long to);
//
// 摘要:
// 向请求添加从请求数据的开始处或结束处计算的特定范围的 Range 标头。
//
// 参数:
// rangeSpecifier:
// 范围说明。
//
// range:
// 范围的开始点或结束点。
//
// 异常:
// System.ArgumentNullException:
// rangeSpecifier 为 null。
//
// System.ArgumentException:
// rangeSpecifier 无效。
//
// System.InvalidOperationException:
// 未能添加范围标头。
public void AddRange(string rangeSpecifier, int range);
//
// 摘要:
// 向请求添加从请求数据的开始处或结束处计算的特定范围的 Range 标头。
//
// 参数:
// rangeSpecifier:
// 范围说明。
//
// range:
// 范围的开始点或结束点。
//
// 异常:
// System.ArgumentNullException:
// rangeSpecifier 为 null。
//
// System.ArgumentException:
// rangeSpecifier 无效。
//
// System.InvalidOperationException:
// 未能添加范围标头。
public void AddRange(string rangeSpecifier, long range);
//
// 摘要:
// 向请求添加指定范围的范围标头。
//
// 参数:
// rangeSpecifier:
// 范围说明。
//
// from:
// 开始发送数据的位置。
//
// to:
// 停止发送数据的位置。
//
// 异常:
// System.ArgumentNullException:
// rangeSpecifier 为 null。
//
// System.ArgumentOutOfRangeException:
// from大于to。- 或 -from 或 to 小于 0。
//
// System.ArgumentException:
// rangeSpecifier 无效。
//
// System.InvalidOperationException:
// 未能添加范围标头。
public void AddRange(string rangeSpecifier, int from, int to);
//
// 摘要:
// 向请求添加指定范围的范围标头。
//
// 参数:
// rangeSpecifier:
// 范围说明。
//
// from:
// 开始发送数据的位置。
//
// to:
// 停止发送数据的位置。
//
// 异常:
// System.ArgumentNullException:
// rangeSpecifier 为 null。
//
// System.ArgumentOutOfRangeException:
// from大于to。- 或 -from 或 to 小于 0。
//
// System.ArgumentException:
// rangeSpecifier 无效。
//
// System.InvalidOperationException:
// 未能添加范围标头。
public void AddRange(string rangeSpecifier, long from, long to);
//
// 摘要:
// 开始对用来写入数据的 System.IO.Stream 对象的异步请求。
//
// 参数:
// callback:
// System.AsyncCallback 委托。
//
// state:
// 此请求的状态对象。
//
// 返回结果:
// 引用该异步请求的 System.IAsyncResult。
//
// 异常:
// System.Net.ProtocolViolationException:
// System.Net.HttpWebRequest.Method 属性为 GET 或 HEAD。- 或 -System.Net.HttpWebRequest.KeepAlive
// 为 true,System.Net.HttpWebRequest.AllowWriteStreamBuffering 为 false,System.Net.HttpWebRequest.ContentLength
// 为 -1,System.Net.HttpWebRequest.SendChunked 为 false,System.Net.HttpWebRequest.Method
// 为 POST 或 PUT。
//
// System.InvalidOperationException:
// 流正由上一个 System.Net.HttpWebRequest.BeginGetRequestStream(System.AsyncCallback,System.Object)
// 调用使用。- 或 -System.Net.HttpWebRequest.TransferEncoding 被设置为一个值,并且 System.Net.HttpWebRequest.SendChunked
// 为 false。- 或 -线程池中的线程即将用完。
//
// System.NotSupportedException:
// 请求缓存验证程序指示对此请求的响应可从缓存中提供;但是写入数据的请求不得使用缓存。如果您正在使用错误实现的自定义缓存验证程序,则会发生此异常。
//
// System.Net.WebException:
// System.Net.HttpWebRequest.Abort() 以前被调用过。
//
// System.ObjectDisposedException:
// 在 .NET Compact Framework 应用程序中,未正确获得和关闭一个内容长度为零的请求流。有关处理内容长度为零的请求的更多信息,请参见
// .NET Compact Framework 中的网络编程。
public override IAsyncResult BeginGetRequestStream(AsyncCallback callback, object state);
//
// 摘要:
// 开始对 Internet 资源的异步请求。
//
// 参数:
// callback:
// System.AsyncCallback 委托
//
// state:
// 此请求的状态对象。
//
// 返回结果:
// 引用对响应的异步请求的 System.IAsyncResult。
//
// 异常:
// System.InvalidOperationException:
// 流正由上一个 System.Net.HttpWebRequest.BeginGetResponse(System.AsyncCallback,System.Object)
// 调用使用- 或 -System.Net.HttpWebRequest.TransferEncoding 被设置为一个值,并且 System.Net.HttpWebRequest.SendChunked
// 为 false。- 或 -线程池中的线程即将用完。
//
// System.Net.ProtocolViolationException:
// System.Net.HttpWebRequest.Method 为 GET 或 HEAD,且 System.Net.HttpWebRequest.ContentLength
// 大于零或 System.Net.HttpWebRequest.SendChunked 为 true。- 或 -System.Net.HttpWebRequest.KeepAlive
// 为 true,System.Net.HttpWebRequest.AllowWriteStreamBuffering 为 false,同时 System.Net.HttpWebRequest.ContentLength
// 为 -1,System.Net.HttpWebRequest.SendChunked 为 false,或者 System.Net.HttpWebRequest.Method
// 为 POST 或 PUT。
//
// System.Net.WebException:
// System.Net.HttpWebRequest.Abort() 以前被调用过。
public override IAsyncResult BeginGetResponse(AsyncCallback callback, object state);
//
// 摘要:
// 结束对用于写入数据的 System.IO.Stream 对象的异步请求。
//
// 参数:
// asyncResult:
// 流的待定的请求。
//
// 返回结果:
// 用来写入请求数据的 System.IO.Stream。
//
// 异常:
// System.ArgumentNullException:
// asyncResult 为 null。
//
// System.IO.IOException:
// 请求未完成,没有可用的流。
//
// System.ArgumentException:
// 当前实例没有从 System.Net.HttpWebRequest.BeginGetRequestStream(System.AsyncCallback,System.Object)
// 调用返回 asyncResult。
//
// System.InvalidOperationException:
// 以前使用 asyncResult 调用过此方法。
//
// System.Net.WebException:
// System.Net.HttpWebRequest.Abort() 以前被调用过。- 或 -处理请求时发生错误。
public override Stream EndGetRequestStream(IAsyncResult asyncResult);
//
// 摘要:
// 结束对用于写入数据的 System.IO.Stream 对象的异步请求,并输出与该流关联的 System.Net.TransportContext。
//
// 参数:
// asyncResult:
// 流的待定的请求。
//
// context:
// System.IO.Stream 的 System.Net.TransportContext。
//
// 返回结果:
// 用来写入请求数据的 System.IO.Stream。
//
// 异常:
// System.ArgumentException:
// 当前实例没有从 System.Net.HttpWebRequest.BeginGetRequestStream(System.AsyncCallback,System.Object)
// 调用返回 asyncResult。
//
// System.ArgumentNullException:
// asyncResult 为 null。
//
// System.InvalidOperationException:
// 以前使用 asyncResult 调用过此方法。
//
// System.IO.IOException:
// 请求未完成,没有可用的流。
//
// System.Net.WebException:
// System.Net.HttpWebRequest.Abort() 以前被调用过。- 或 -处理请求时发生错误。
public Stream EndGetRequestStream(IAsyncResult asyncResult, out TransportContext context);
//
// 摘要:
// 结束对 Internet 资源的异步请求。
//
// 参数:
// asyncResult:
// 挂起的对响应的请求。
//
// 返回结果:
// 包含来自 Internet 资源的响应的 System.Net.WebResponse。
//
// 异常:
// System.ArgumentNullException:
// asyncResult 为 null。
//
// System.InvalidOperationException:
// 以前使用 asyncResult 调用过此方法。- 或 -System.Net.HttpWebRequest.ContentLength 属性大于
// 0,但是数据尚未写入请求流。
//
// System.Net.WebException:
// System.Net.HttpWebRequest.Abort() 以前被调用过。- 或 -处理请求时发生错误。
//
// System.ArgumentException:
// 当前实例没有从 System.Net.HttpWebRequest.BeginGetResponse(System.AsyncCallback,System.Object)
// 调用返回 asyncResult。
public override WebResponse EndGetResponse(IAsyncResult asyncResult);
//
// 摘要:
// 使用序列化目标对象所需的数据填充 System.Runtime.Serialization.SerializationInfo。
//
// 参数:
// serializationInfo:
// 要填充数据的 System.Runtime.Serialization.SerializationInfo。
//
// streamingContext:
// 用于指定该序列化的目标的 System.Runtime.Serialization.StreamingContext。
protected override void GetObjectData(SerializationInfo serializationInfo, StreamingContext streamingContext);
//
// 摘要:
// 获取用于写入请求数据的 System.IO.Stream 对象。
//
// 返回结果:
// 用来写入请求数据的 System.IO.Stream。
//
// 异常:
// System.Net.ProtocolViolationException:
// System.Net.HttpWebRequest.Method 属性为 GET 或 HEAD。- 或 -System.Net.HttpWebRequest.KeepAlive
// 为 true,System.Net.HttpWebRequest.AllowWriteStreamBuffering 为 false,System.Net.HttpWebRequest.ContentLength
// 为 -1,System.Net.HttpWebRequest.SendChunked 为 false,System.Net.HttpWebRequest.Method
// 为 POST 或 PUT。
//
// System.InvalidOperationException:
// System.Net.HttpWebRequest.GetRequestStream() 方法被调用多次。- 或 -System.Net.HttpWebRequest.TransferEncoding
// 被设置为一个值,并且 System.Net.HttpWebRequest.SendChunked 为 false。
//
// System.NotSupportedException:
// 请求缓存验证程序指示对此请求的响应可从缓存中提供;但是写入数据的请求不得使用缓存。如果您正在使用错误实现的自定义缓存验证程序,则会发生此异常。
//
// System.Net.WebException:
// System.Net.HttpWebRequest.Abort() 以前被调用过。- 或 -请求的超时期限到期。- 或 -处理请求时发生错误。
//
// System.ObjectDisposedException:
// 在 .NET Compact Framework 应用程序中,未正确获得和关闭一个内容长度为零的请求流。有关处理内容长度为零的请求的更多信息,请参见
// .NET Compact Framework 中的网络编程。
public override Stream GetRequestStream();
//
// 摘要:
// 获取用于写入请求数据的 System.IO.Stream 对象,并输出与该流关联的 System.Net.TransportContext。
//
// 参数:
// context:
// System.IO.Stream 的 System.Net.TransportContext。
//
// 返回结果:
// 用来写入请求数据的 System.IO.Stream。
//
// 异常:
// System.Exception:
// System.Net.HttpWebRequest.GetRequestStream() 方法无法获取 System.IO.Stream。
//
// System.InvalidOperationException:
// System.Net.HttpWebRequest.GetRequestStream() 方法被调用多次。- 或 -System.Net.HttpWebRequest.TransferEncoding
// 被设置为一个值,并且 System.Net.HttpWebRequest.SendChunked 为 false。
//
// System.NotSupportedException:
// 请求缓存验证程序指示对此请求的响应可从缓存中提供;但是写入数据的请求不得使用缓存。如果您正在使用错误实现的自定义缓存验证程序,则会发生此异常。
//
// System.Net.ProtocolViolationException:
// System.Net.HttpWebRequest.Method 属性为 GET 或 HEAD。- 或 -System.Net.HttpWebRequest.KeepAlive
// 为 true,System.Net.HttpWebRequest.AllowWriteStreamBuffering 为 false,System.Net.HttpWebRequest.ContentLength
// 为 -1,System.Net.HttpWebRequest.SendChunked 为 false,System.Net.HttpWebRequest.Method
// 为 POST 或 PUT。
//
// System.Net.WebException:
// System.Net.HttpWebRequest.Abort() 以前被调用过。- 或 -请求的超时期限到期。- 或 -处理请求时发生错误。
public Stream GetRequestStream(out TransportContext context);
//
// 摘要:
// 返回来自 Internet 资源的响应。
//
// 返回结果:
// 包含来自 Internet 资源的响应的 System.Net.WebResponse。
//
// 异常:
// System.InvalidOperationException:
// 流正由上一个 System.Net.HttpWebRequest.BeginGetResponse(System.AsyncCallback,System.Object)
// 调用使用。- 或 -System.Net.HttpWebRequest.TransferEncoding 被设置为一个值,并且 System.Net.HttpWebRequest.SendChunked
// 为 false。
//
// System.Net.ProtocolViolationException:
// System.Net.HttpWebRequest.Method 为 GET 或 HEAD,并且或者 System.Net.HttpWebRequest.ContentLength
// 大于或等于零,或者 System.Net.HttpWebRequest.SendChunked 为 true。- 或 -System.Net.HttpWebRequest.KeepAlive
// 为 true,System.Net.HttpWebRequest.AllowWriteStreamBuffering 为 false,System.Net.HttpWebRequest.ContentLength
// 为 -1,System.Net.HttpWebRequest.SendChunked 为 false,System.Net.HttpWebRequest.Method
// 为 POST 或 PUT。
//
// System.NotSupportedException:
// 请求缓存验证程序指示对此请求的响应可从缓存中提供;但是,此请求包含要发送到服务器的数据。发送数据的请求不得使用缓存。如果您正在使用错误实现的自定义缓存验证程序,则会发生此异常。
//
// System.Net.WebException:
// System.Net.HttpWebRequest.Abort() 以前被调用过。- 或 -请求的超时期限到期。- 或 -处理请求时发生错误。
public override WebResponse GetResponse();
}
}

可以明显的看到windows phone项目中没有

GetResponse这个方法,而在控制台程序中就有,这是为什么?
支持(0) 反对(0) learnWindowsPhone | 园豆:38 (初学一级) | 2012-04-02 22:33
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册