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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章