本文摘自PHP中文网,作者巴扎黑,侵删。
C#CS发送HTTP GET请求 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | try
{
WebRequest req = WebRequest.Create( "http://127.0.0.1/test/loginsso.aspx?username=admin&password=admin" );
req.Method = "POST" ;
Stream postStream = req.GetRequestStream();
postStream.Close();
WebResponse res = req.GetResponse();
System.Text.Encoding resEncoding = System.Text.Encoding.GetEncoding( "utf-8" );
StreamReader reader = new StreamReader(res.GetResponseStream(), resEncoding);
string html = reader.ReadToEnd();
MessageBox.Show( "=========" + html);
reader.Close();
res.Close();
}
catch (Exception ex)
{
MessageBox.Show( "error" );
}
|
.NET接收GET发送请求
1 2 3 4 5 6 7 8 9 10 11 12 | Response.ContentEncoding = Encoding.GetEncoding( "UTF-8" );
string username = Request[ "username" ];
string password = Request[ "password" ];
if (username != "" && username == "admin" && password != "" && password == "admin" )
{
Response.Write( "success" );
}
else
{
Response.Write( "error" + Request.Url.Host);
}
|
.NET接收后请求
1 2 3 4 | System.Text.Encoding resEncoding = System.Text.Encoding.GetEncoding( "utf-8" );
StreamReader reader = new StreamReader(Request.InputStream, resEncoding);
string msg = reader.ReadToEnd();
reader.Close();
|
C#CS发送图片附件
C#代码
1 2 3 4 5 6 7 8 9 10 11 12 | 如果 (!textBox_fileName.Text.Trim()。等于(“” ))
{
字符串 的loadFile = textBox_fileName.Text.Trim();
字符串 文件名= loadFile.Substring(loadFile.LastIndexOf(“\\”)+1,loadFile.Length - 1 - loadFile.LastIndexOf(“ \\”));
字符串 urlStr = @ “http:
UploadFileBinary(的loadFile,urlStr);
}
其他
{
字符串 alStr = “您还没有选择文件” ;
MessageBox.Show(alStr, “ 系统提示” ,MessageBoxButtons.OK,MessageBoxIcon.Exclamation,MessageBoxDefaultButton.Button1);
}
|
C#代码
阅读剩余部分
相关阅读 >>
C#基础入门-常量详解
详细介绍C#读取xml多级子节点
C#中foreach实例代码
C# 常用函数总集
C# 中guid生成格式有哪些方法
C#实现添加word文本与图片超链接的方法
关于.net(C#)正确读取中文编码文件的实例教程
C#执行原理深入解析(图文)
关于.net使用cache框架如何给程序添加cache的实例
.net core对mongodb执行多条件查询
更多相关阅读请进入《C#》频道 >>
清华大学出版社
作者:[美]克里斯琴·内格尔(Christian Nagel)著。出版时间:2019年3月。
转载请注明出处:木庄网络博客 » C#CS与BS数据请求交换