社区
C#
帖子详情
在Winform中如何向http目标地址以post的方式提交请求,并抓取页面输出内容呢?
lcy_008
2006-06-22 09:19:37
如题。100送上。
...全文
785
8
打赏
收藏
在Winform中如何向http目标地址以post的方式提交请求,并抓取页面输出内容呢?
如题。100送上。
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
8 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
shalen520
2006-06-22
打赏
举报
回复
//这个新建的Cookie集合不知道有什么用??
//req.CookieContainer =new CookieContainer ();
=================================================
如果需要在请求之间保存Session状态,就有用了
固执的染色体
2006-06-22
打赏
举报
回复
mark
blestcc
2006-06-22
打赏
举报
回复
#region get数据类GetDate
/// <summary>
/// Get数据类
/// </summary>
public class GetDate
{
private string sPostUrl;
/// <summary>
/// 提交地址
/// </summary>
public string postUrl
{
get
{
return sPostUrl;
}
set
{
sPostUrl=value;
}
}
private CookieContainer sSessionId;
/// <summary>
/// Cookies标志
/// </summary>
public CookieContainer SessionId
{
get
{
return sSessionId;
}
set
{
sSessionId=value;
}
}
private string sReturnString;
/// <summary>
/// 返回字符串
/// </summary>
/// <returns></returns>
public string ReturnString
{
get
{
return sReturnString;
}
set
{
sReturnString=value;
}
}
public void Send()
{
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(sPostUrl);
request.CookieContainer=sSessionId;
request.Method="get";
//request.Timeout=2240;
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
byte[] buf = new byte[1024];
int count=0;
while(true)
{
//resStream.Write(byte1,0,byte1.Length);
count = response.GetResponseStream().Read(buf, 0, buf.Length);
if (count<=0)
{
break;
}
sReturnString+=Encoding.Unicode.GetString(buf,0,count);
}
}
}
#endregion
我看你有戏
2006-06-22
打赏
举报
回复
public static void PostDate()
{
//建立登录检查地址
string url = @"http://howaa.baoyaa.com/smslt.asp";
//建立request对象
System.Net.HttpWebRequest req=(System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(url);
//这个新建的Cookie集合不知道有什么用??
//req.CookieContainer =new CookieContainer ();
req.Method="POST";//POST方式请求
req.ContentType= "application/x-www-form-urlencoded";//内容类型
//参数经过URL编码
string paraUrlCoded;
paraUrlCoded=System.Web.HttpUtility.UrlEncode("MobilePhone") +"="+System.Web.HttpUtility.UrlEncode("13564250347");
// paraUrlCoded+="&";
// paraUrlCoded+=System.Web.HttpUtility.UrlEncode("passwd")+"="+System.Web.HttpUtility.UrlEncode("999999");
//将URL编码后的字符串转化为字节
try
{
byte[] payload;
payload=System.Text.Encoding.UTF8.GetBytes(paraUrlCoded);
req.ContentLength=payload.Length; //设置请求的ContentLength
System.IO.Stream writer=req.GetRequestStream();//获得请求流
writer.Write(payload,0,payload.Length);//将请求参数写入流
writer.Close();//关闭请求流
}
catch
{}
//获得响应流
}
Yuna_2z
2006-06-22
打赏
举报
回复
MARK
shalen520
2006-06-22
打赏
举报
回复
using System.Net;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://abc.com.cn/xyz.aspx");
//构造要post的数据
ASCIIEncoding encoding=new ASCIIEncoding();
string postdata="a=xxx&b=xxx";
byte[] byte1=encoding.GetBytes(postdata);
//Post
req.Method = "POST";
req.ContentType="application/x-www-form-urlencoded";
req.ContentLength=postdata.Length;
Stream s=req.GetRequestStream();
s.Write(byte1,0,byte1.Length);
s.Close();
//获取响应
HttpWebResponse rp= (HttpWebResponse)req.GetResponse();
Stream rps= rp.GetResponseStream();
StreamReader sr= new StreamReader(rps);
//获得响应字符串
string result = sr.ReadToEnd();
rp.Close();
YAOHE
2006-06-22
打赏
举报
回复
System.Text.Encoding encode = System.Text.Encoding.GetEncoding("GB2312");
tmpurl="请求URL信息";
System.Net.WebClient wc=new WebClient();
System.IO.StreamReader sr=new System.IO.StreamReader( wc.OpenRead(tmpurl),encode);
tmpurl="";
tmpurl=sr.ReadToEnd();
tmpurl即取得返回所有信息
lcy_008
2006-06-22
打赏
举报
回复
调用webclient执行postdata么?
C#通过GET/
POST
方式
发送
Http
请求
本文详细对比了
HTTP
请求
中
的GET与
POST
方法的区别,包括参数传递
方式
、传输数据大小限制及安全性等方面,并提供了使用C#语言实现这两种
请求
方式
的具体代码示例。
C#
Winform
发送
HTTP
请求
本文介绍了一个使用 C# 在
Winform
应用
中
发送
HTTP
GET 和
POST
请求
的方法。详细展示了如何创建
请求
,设置参数,处理响应,并提供了发送 JSON 数据的示例。
C#
winform
请求
http
( get ,
post
两种
方式
)
本文详细介绍了如何使用.NET
中
的
Http
WebRequest和
Http
WebResponse类实现
HTTP
请求
,并对比了GET与
POST
两种
请求
方式
的区别,包括数据传输
方式
、安全性及容量限制等。
Winform
模拟
post
请求
和get
请求
登录网站
本文详细介绍了如何使用
Winform
模拟
POST
请求
登录网站,通过分析
HTTP
请求
报文和响应报文的结构,讲解了GET与
POST
的区别,并提供了C#代码示例来实现
POST
请求
。同时,讨论了
HTTP
状态码、
请求
头字段如Accept、User-Agent等的作用,以及GET和
POST
在安全性上的差异。
.net
post
提交
后接收返回数据_
Winform
模拟
post
请求
和get
请求
登录网站
本文介绍如何使用
WinForm
模拟
POST
请求
登录网站的过程,并详细解释
HTTP
请求
与响应报文的结构,对比GET与
POST
的区别。
C#
111,129
社区成员
642,541
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章