本文摘自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#给pdf文档添加注释的示例代码分享(图)
.net下如何使用quartz.net的代码图文教程
C#中tostring数据类型格式大全(千分符)总结
详细概述C#中的常用字符串方法
C#中关于timer定时器重入问题的解决方法
.net中怎么实现程序分页
详细介绍使用msscriptcontrol在C#中读取json数据的方法
C#基于正则表达式如何删除字符串中数字或非数字的方法详解
C#开发实例-订制屏幕截图工具(一)功能概览(图)
C#中值类型和引用类型简单概述
更多相关阅读请进入《C#》频道 >>
清华大学出版社
作者:[美]克里斯琴·内格尔(Christian Nagel)著。出版时间:2019年3月。
转载请注明出处:木庄网络博客 » C#CS与BS数据请求交换