社区
C#
帖子详情
提问:如何用C#做HTTP的POST方法请求
boymaster
2005-12-28 10:35:12
本人最初刚开始接触,请大虾们帮帮忙
C#如何用HTTP以text/plain方式来POST一个xml文件的内容!!!
在线期待中……
...全文
991
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
1. **API调用**:学习如何在
C#
中发起
HTTP
请求
,通常使用
Http
Client类,发送GET或
POST
请求
到指定的API接口。 2. **JSON解析**:API响应通常以JSON格式返回,开发者需要了解如何使用Json.NET或其他库解析和操作JSON...
C#
Socket编程经典教程
- **
HTTP
请求
解析**: 了解
HTTP
请求
的基本结构,如
请求
方法
(GET、
POST
等)、URL、头部信息等。 - **响应构建**: 学习如何构造
HTTP
响应消息,包括状态码、头部信息以及可能的响应体数据。 - **示例**: 使用
C#
...
Q750623 问题的回答
C#
http
webrequest
4. **
POST
数据**:如果要发送
POST
请求
,可以使用`GetRequestStream()`写入数据: ```csharp request.ContentType = "application/x-www-form-urlencoded"; using (StreamWriter writer = new StreamWriter(request....
C#
打开php链接传参然后接收返回值的关键代码
在
C#
中,我们需要构造一个
HTTP
POST
请求
,将参数封装在
请求
体中,并发送到PHP服务器。以下是如何实现的示例: ```csharp using System; using System.IO; using System.Net; public class Program { public ...
PlayAdvApi:APIAdventure的简单控制台客户端
C#
中的System.Net命名空间提供了
Http
Client类,可以方便地发送GET、
POST
等
HTTP
请求
。PlayAdvApi可能使用
Http
Client发送登录、查询、操作等
请求
,并解析服务器返回的数据。 4. JSON序列化与反序列化: 服务器通常会...
C#
111,098
社区成员
642,554
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章