C# HttpHelper萬能框架實現 接口


POST請請求是使用Http協議與請求的URL進行連接,然后再寫入數據,最后關閉連接的過程

方法(1)

    

//要Post的數據
string postdate = "a=123&c=456&d=789" ;
//將Post數據轉為字節數組
byte [] bytedate = System.Text.Encoding.UTF8.GetBytes(postdate);
//創建Httphelper對象
HttpHelper http = new HttpHelper();
//創建Httphelper參數對象
HttpItem item = new HttpItem()
{
     URL = "http://www.sufeinet.com" ,//URL     必需項   
     Method = "post" , //URL     可選項 默認為Get  
     ContentType = "application/x-www-form-urlencoded" , //返回類型    可選項有默認值
     PostDataType = PostDataType.Byte,
     PostdataByte = bytedate
};
//請求的返回值對象
HttpResult result = http.GetHtml(item);
//獲取請請求的Html
string html = result.Html;
//獲取請求的Cookie
string cookie = result.Cookie;
 
 
 
方法(2)

public static string Url = System.Web.Configuration.WebConfigurationManager.AppSettings["RemoteUrl"];
        public static void Add(FaceItem item) {


            try
            {
                HttpHelper http = new HttpHelper();
                HttpItem hitem = new HttpItem()
                {

                    Method = "post",//URL     可選項 默認為Get  
                    ContentType = "application/x-www-form-urlencoded",
                    URL = Url + "add.action",
                    Postdata = string.Format("f_Id=1&imgLen={0}&imgContent={1}&name={2}&info=",
                                              item.UserGuid, item.ImgLength, item.ImgContent)
                };

                HttpResult result = http.GetHtml(hitem);
                //獲取請請求的Html
                string html = result.Html;
                //獲取請求的Cookie
                string cookie = result.Cookie;
               // item.ImageId = Guid.NewGuid().ToString();
            }
            catch(Exception ex) {
                //記錄錯誤
            }

            //測試使用
            item.ImageId = Guid.NewGuid().ToString();

        }

蘇飛論壇

http://www.sufeinet.com/thread-9993-1-1.html

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM