C#中使用post请求方法请求表单-用于两个网站的交互
生活随笔
收集整理的這篇文章主要介紹了
C#中使用post请求方法请求表单-用于两个网站的交互
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
網(wǎng)站A中的后臺代碼:
1 //請求的URL 2 HttpWebRequest request = WebRequest.Create("http://192.168.1.132:86/test01.aspx") as HttpWebRequest; 3 request.Method = "post"; 4 5 string data = "傳輸?shù)臄?shù)據(jù)"; 6 //List<string> list = new List<string>(data); 7 //string newdata = jsonHelper.GetJSON<List<string>> (list); 8 byte[] bytes = Encoding.Default.GetBytes(data); 9 request.ContentLength = bytes.Length; 10 request.ContentType = "application/x-www-form-urlencoded"; 11 Stream sw = request.GetRequestStream(); 12 sw.Write(bytes, 0, bytes.Length); 13 sw.Close(); 14 15 HttpWebResponse resp = request.GetResponse() as HttpWebResponse; 16 Stream st = resp.GetResponseStream(); 17 StreamReader sr = new StreamReader(st); 18 string returnValue = sr.ReadToEnd(); 19 sr.Close(); 20 Response.Write(returnValue); 請求網(wǎng)站A的后臺代碼網(wǎng)站B中的后臺代碼:
1 if (Request.HttpMethod.ToUpper()=="POST") 2 { 3 Stream input =Request.InputStream; 4 StreamReader sr = new System.IO.StreamReader(input,Encoding.Default); 5 string s=sr.ReadToEnd(); 6 sr.Close(); 7 sr.Dispose(); 8 9 Response.Write("<script>alert('你輸入的是:"+s+"');</script>"); 10 Response.End(); 11 } 被請求網(wǎng)站B的后臺代碼?
轉載于:https://www.cnblogs.com/wangliqiang1026/p/4505340.html
總結
以上是生活随笔為你收集整理的C#中使用post请求方法请求表单-用于两个网站的交互的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MVC PartialView
- 下一篇: System.FormatExcepti