日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

HttpWebRequest post提交XMl参数请求,

發布時間:2024/9/20 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HttpWebRequest post提交XMl参数请求, 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
public string StartPing(string pingURL)//改為一個傳參數URL { StreamReader sr = null; StringBuilder sb = new StringBuilder(); string strOutput = string.Empty; string strXML = string.Empty; try { //HttpUtility.HtmlEncode strXML = BuildXML(); int len = strXML.Length; ASCIIEncoding ascii = new ASCIIEncoding(); HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(pingURL); webReq.Method = "POST"; webReq.Timeout = 3000;//超時為3秒 webReq.ContentType = "text/xml"; //string contenttype = "application/x-www-form-urlencoded";//更網站該方法支持的類型要一致 webReq.Credentials = CredentialCache.DefaultNetworkCredentials; webReq.ContentLength = len;Stream streamRequest = webReq.GetRequestStream(); byte[] bt = ascii.GetBytes(strXML); streamRequest.Write(bt, 0, len); HttpWebResponse webRes = (HttpWebResponse)webReq.GetResponse();sr = new StreamReader(webRes.GetResponseStream(), Encoding.ASCII); string ret = sr.ReadToEnd(); sb.AppendLine("\n"); sb.AppendLine(ret);if (ret.IndexOf("<boolean>0</boolean>") >= 0) { sb.AppendLine("\n\t 服務提交成功!"); } else if (ret.IndexOf("<boolean>1</boolean>") >= 0) { sb.AppendLine("\n\t 服務提交失敗!"); } if (sr != null) { sr.Close(); } } catch (Exception ex) { sb.AppendLine(ex.Message); sb.AppendLine(ex.StackTrace); } finally { strOutput = sb.ToString(); if (sr != null) { sr.Dispose(); } } return strOutput; }private string BuildXML() { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("<?xml version=\"1.0\"?>"); sb.Append("<params>"); sb.AppendFormat("<title>{0}", "公告標題"); sb.Append("</title>"); sb.AppendFormat("<content>{0}", "公告內容,base64加密的"); sb.Append("</content>");sb.Append("<verify=be10c510b5f4f082dbd4268820cde895>");sb.Append("</params>"); return sb.ToString(); }

下面是服務器端接收請求方法:

加載事件里: //對應方法StartPingbyte[] byts = new byte[Request.InputStream.Length];Request.InputStream.Read(byts, 0, byts.Length);string req = System.Text.Encoding.Default.GetString(byts);req = Server.UrlDecode(req);//下面是接收到的內容//<?xml version="1.0"?><params><title>????</title><content>?????base64???</content><verify=be10c510b5f4f082dbd4268820cde895></params>*/

總結

以上是生活随笔為你收集整理的HttpWebRequest post提交XMl参数请求,的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。