コード例 #1
0
ファイル: WeChatMenu.ashx.cs プロジェクト: eatage/WeChatMenu
 /// <summary>
 /// HttpPost访问
 /// </summary>
 public string HttpPost(string Url, string Params)
 {
     HTTPERROR = string.Empty;
     System.Net.WebClient webClient = new System.Net.WebClient();
     webClient.Headers.Add("Accept", "*/*");
     webClient.Headers.Add("Accept-Language", "zh-cn");
     webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
     webClient.Headers.Add("User-Agent", "Baiduspider+(+http://www.baidu.com/search/spider.htm)");
     //将字符串转换成字节数组
     byte[] postData = System.Text.Encoding.GetEncoding("utf-8").GetBytes(Params);
     try
     {
         byte[] responseData = webClient.UploadData(Url, "POST", postData);
         return(System.Text.Encoding.GetEncoding("utf-8").GetString(responseData));
     }
     catch (System.Exception Exce)
     {
         HTTPERROR = Exce.ToString();
         return("-1," + Exce.ToString());
     }
     finally
     {
         if (webClient != null)
         {
             webClient.Dispose();
         }
         if (webClient != null)
         {
             webClient = null;
         }
     }
 }
コード例 #2
0
ファイル: Tools.cs プロジェクト: jackjet870/WeixinShop
 public static string of_SendPost_utf8(string Url, string Params)
 {
     // 初始化WebClient
     System.Net.WebClient webClient = new System.Net.WebClient();
     webClient.Headers.Add("Accept", "*/*");
     webClient.Headers.Add("Accept-Language", "zh-cn");
     webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
     //将字符串转换成字节数组
     byte[] postData = Encoding.GetEncoding("utf-8").GetBytes(Params);
     try
     {
         byte[] responseData = webClient.UploadData(Url, "POST", postData);
         string srcString    = Encoding.GetEncoding("utf-8").GetString(responseData);
         return(srcString.Trim());
     }
     catch (Exception Exce)
     {
         return("-1," + Exce.ToString() + "\r\n" + Url + "    " + Params);
     }
 }