用.NET C# 发送HTTP 请求,返回结果
来源:互联网 发布:我要买微信木马软件 编辑:程序博客网 时间:2024/04/28 04:14
1、方法一
public string SendPostHttp( string Url,string datastr)
{
try
{
byte[] data = System.Text.Encoding.GetEncoding ("GB2312").GetBytes ( datastr ) ;
// 准备请求...
HttpWebRequest req = (HttpWebRequest) WebRequest.Create ( Url ) ;
req.Method = "Post" ; //Get or Post
req.ContentType ="application/x-www-form-urlencoded";
req.ContentLength = data.Length ;
Stream stream = req.GetRequestStream () ;
// 发送数据
stream.Write ( data ,0 ,data.Length ) ;
stream.Close () ;
HttpWebResponse rep = (HttpWebResponse)req.GetResponse();
Stream receiveStream = rep.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("GB2312");
// Pipes the stream to a higher level stream reader with the required encoding format.
StreamReader readStream = new StreamReader( receiveStream, encode );
Char[] read = new Char[256];
int count = readStream.Read( read, 0, 256 );
StringBuilder sb = new StringBuilder ("") ;
while (count > 0)
{
String readstr = new String(read, 0, count);
sb.Append ( readstr ) ;
count = readStream.Read(read, 0, 256);
}
rep.Close();
readStream.Close();
return sb.ToString () ;
}
catch(Exception ex)
{
return "" ;
}
}
调用 SendPostHttp( 'http://www.abc.com/abc.php', "?Name=cc&PWD=123")
2、方法二
WebClient c = new WebClient();
byte[] ret = c.DownloadData("http://www.abc.com/register.php?id=11&account=" + UserName + "&password=" + UserMd5( UserPwd ) );
string srcString = Encoding.UTF8.GetString(ret);
string[] values = srcString.Split(',');
if (values[0] == "SUCCESS")
return values[1].ToString();
else
return "FAILED";
- 用.NET C# 发送HTTP 请求,返回结果
- 用PHP发送HTTP POST 请求,获得返回结果。(转)
- MFC怎样发送http请求并接受返回的结果?
- C#发送HTTP请求
- C#发送 http请求
- C#发送http请求
- HttpClient 发送Json请求,结果返回Json
- httpclient发送Json请求,结果返回Json.
- JAVA 使用HttpClient 实现简单发送HTTP请求 无返回结果
- Android--使用Http向服务器发送请求并取得返回结果,下载图片
- Android--使用Http向服务器发送请求并取得返回结果,下载图片
- WinHttp方法通过HTTP协议向服务器发送请求,返回结果
- C#后台发送Http请求
- C#后台发送HTTP请求
- Http请求返回结果报UnsupportedCharsetException
- Http请求长时间等待无结果返回
- Java发送Http请求,解析html返回
- Java发送Http请求,解析html返回
- Template模式
- 从现在开始
- MySQL 各种数据类型
- Myeclipse+Weblogic配置详解
- 在eclipse中开发struts2应用
- 用.NET C# 发送HTTP 请求,返回结果
- 利用Linux Shell 修改所有子目录下的文件权限
- Web.config参数详解
- [zz][原创]MYSQL大小写的约定
- SQL2000学习 Update
- Visual C# 打造 “浏览器”
- 转载:关于预编译头文件
- kbfiltr.sys的安装问题
- 有什么工具能提供预编译后的源代码啊?http://expert.csdn.net/Handler.ashx?id=1943733