本文摘自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#单位转换器的图文代码详细介绍
.net的错误处理机制是什么
vs寻找C#的运行库文件
总结.net mvc实现长轮询实例
C#中的数据类型是什么?C#中的四种数据类型解释
C# .net 将list序列化
c#中var和dynamic之间的区别是什么?
使用c#操作windowad之的windows用户组
C# winform制作不规则窗体(代码)
C#获取系统当前鼠标的图案示例代码
更多相关阅读请进入《C#》频道 >>
清华大学出版社
作者:[美]克里斯琴·内格尔(Christian Nagel)著。出版时间:2019年3月。
转载请注明出处:木庄网络博客 » C#CS与BS数据请求交换