WP网络编程

1.WebClient
主要应用场景:
     1)简单的GET和POST应用场景
     2)在WP里面只有异步的方法
     3)不支持cookies,但是这个有办法

  public class CookieSupportedWebClient GZipWebClient
    {
        [ SecuritySafeCritical ]
        public CookieSupportedWebClient ()
        {
            CookieContainer new CookieContainer();
        }

        public CookieContainer CookieContainer { get set ; }

        protected override WebRequest GetWebRequest (Uri address)
        {
            WebRequest request base. GetWebRequest (address );

            if (request is HttpWebRequest )
                ( request as HttpWebRequest). CookieContainer CookieContainer ;
            return request ;
        }
    }

2.HttpRequest
主要应用场景:
     1)GET POST PUT DELETE 都支持,手段比WebClient丰富
     2)写起来比较麻烦,尤其是POST方法
     3)支持content type: Multipart,但是WP里面弄还是有点麻烦,不支持直接用地址

3.SharpGISwebclient
http://www.sharpgis.net/post/2011/08/28/GZIP-Compressed-Web-Requests-in-WP7-Take-2.aspx
            
主要应用场景:减少30% 网络流量!!!
     1)如果用webclient的地方可以直接用SharpGISwebclient来替换
     2)还是不支持cookies
     3)现有用着webclient的地方不用修改,主要在app.xmal.cs里面加入以下代码即可
//            WebRequest.RegisterPrefix("http://", SharpGIS.WebRequestCreator.GZip);
//            WebRequest.RegisterPrefix("https://", SharpGIS.WebRequestCreator.GZip);


4.RestSharp
http://restsharp.org/
感觉是个神器!!在github,Nuget都有项目
     1)支持Restful的请求
     2)支持直接反序列话,现在的版本甚至不依赖json.net
     3)有同步和异步的请求方法,可操作的范围比得上HttpRequest
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章