当前位置:   article > 正文

C#WinForm POST方式提交给网页(与网页交互) (转)

winform post 网页

提交(POST):

需要导入命名空间

using System.Net;
using System.IO;

string postData = "username=" + Login_用户名.Text + "&password=" + Login_密码.Text;//POST参数和值写入POSTDATE里
byte[] byteArray = Encoding.Default.GetBytes(postData);
string url = "http://127.0.0.1/user.php"; //POST到网站
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(new Uri(url));
webRequest.Method = "POST";
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.ContentLength = byteArray.Length;
Stream newStream = webRequest.GetRequestStream();
newStream.Write(byteArray, 0, byteArray.Length);
newStream.Close();

 

接收返回信息:

HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
StreamReader php = new StreamReader(response.GetResponseStream(), Encoding.Default);
string Message = php.ReadToEnd();

 

这里的Message即为网页返回的信息!

转载于:https://www.cnblogs.com/kunlunmountain/p/5406795.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/257838
推荐阅读
相关标签
  

闽ICP备14008679号