社区
C#
帖子详情
提问:如何用C#做HTTP的POST方法请求
boymaster
2005-12-28 10:35:12
本人最初刚开始接触,请大虾们帮帮忙
C#如何用HTTP以text/plain方式来POST一个xml文件的内容!!!
在线期待中……
...全文
989
14
打赏
收藏
提问:如何用C#做HTTP的POST方法请求
本人最初刚开始接触,请大虾们帮帮忙 C#如何用HTTP以text/plain方式来POST一个xml文件的内容!!! 在线期待中……
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
14 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
heilong05
2006-06-30
打赏
举报
回复
Encoding encoding = Encoding.GetEncoding("GB2312");
string strUrl = @"http://" + DefaultIP + "" + DefaultUrl + "";
string postData ="username="+UserName+"&password="+password+"&area_c=&telfile1="+TelePhones+"";
byte[] data = encoding.GetBytes(postData);
// 准备HTTP请求...
System.Net.HttpWebRequest myRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(strUrl);
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
System.IO.Stream newStream = myRequest.GetRequestStream();
// 发送数据
newStream.Write(data, 0, data.Length);
newStream.Close();
//HTTP响应
System.Net.HttpWebResponse myResponse = (System.Net.HttpWebResponse)myRequest.GetResponse();
System.IO.Stream receiveStream = myResponse.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("GB2312");
System.IO.StreamReader readStream = new System.IO.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);
}
myResponse.Close();
readStream.Close();
====CSDN 小助手 V2.5 2005年11月05日发布====
CSDN小助手是一款脱离浏览器也可以访问Csdn论坛的软件
界面:http://blog.csdn.net/Qqwwee_Com/archive/2005/11/05/523395.aspx
下载:http://szlawbook.com/csdnv2
固执的染色体
2006-06-30
打赏
举报
回复
mark
blackhero
2006-06-30
打赏
举报
回复
http://www.manbu.net/Lib/Class1/Sub8/1/24.asp
heilong05
2006-06-30
打赏
举报
回复
Mark
dreadknight2
2006-02-15
打赏
举报
回复
学习学习
Qqwwee_Com
2006-02-15
打赏
举报
回复
可以参考我尾巴后面的软件
有源代码的。
====CSDN 小助手 V2.5 2005年11月05日发布====
CSDN小助手是一款脱离浏览器也可以访问Csdn论坛的软件
界面:http://blog.csdn.net/Qqwwee_Com/archive/2005/11/05/523395.aspx
下载:http://szlawbook.com/csdnv2
jrl5365
2006-02-15
打赏
举报
回复
收下了!~以后可能用的着!
ArLi2003
2006-02-15
打赏
举报
回复
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/cpref/html/frlrfSystemNetWebClientClassUploadValuesTopic.htm
webclient 的 uploadXXXXXXXXXX 简单的很,不必webrequest
cmHua
2006-02-14
打赏
举报
回复
收藏起来慢慢看
singlepine
2005-12-29
打赏
举报
回复
http://singlepine.cnblogs.com/articles/292661.html
boymaster
2005-12-29
打赏
举报
回复
HttpWebRequest req = (HttpWebRequest) WebRequest.Create ( LMMPUrl ) ;
LMMPUrl直接写URL吗?类似:http://www.csdn.net吗?
atliu
2005-12-28
打赏
举报
回复
好像是孟子E章上的文章
atliu
2005-12-28
打赏
举报
回复
public static string PostData( string str)
{
try
{
byte[] data = System.Text.Encoding.GetEncoding ("GB2312").GetBytes ( str ) ;
// 准备请求...
HttpWebRequest req = (HttpWebRequest) WebRequest.Create ( LMMPUrl ) ;
req.Method = "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 "" ;
ForumExceptions.Log ( ex ) ;
}
}
s5689412
2005-12-28
打赏
举报
回复
参考MSDN中HttpWebRequest 和 HttpWebResponse 类的内容。
讯飞星火大模型
C#
接入Demo
讯飞星火大模型
C#
接入Demo,可以通过申请个人服务实现API接入,简化开发流程
C#
Socket编程经典教程
自己从网上找来的,学习后真的受益匪浅,很适合新手入门,
C#
Socket编程经典教程
Q750623 问题的回答
C#
http
webrequest
http
s://ask.csdn.net/questions/750623 Q750623 问题的回答
C#
http
webrequest
C#
打开php链接传参然后接收返回值的关键代码
主要介绍了
C#
打开php链接传参然后接收返回值的关键代码,代码简单易懂,非常不错,具有参考借鉴价值,需要的朋友可以参考下
PlayAdvApi:APIAdventure的简单控制台客户端
PlayAdvApi 这是我的冒险服务器的过期客户端。 所有这些代码都是我个人的重任,因为我在工作场所面临新的挑战。 随意问任何问题。
C#
111,097
社区成员
642,554
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章