社区
C#
帖子详情
在Winform中如何向http目标地址以post的方式提交请求,并抓取页面输出内容呢?
lcy_008
2006-06-22 09:19:37
如题。100送上。
...全文
694
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么?
WinForm
关于CefSharp获取后的资源、截取request参数、拦截response数据、注入jquery文件和js代码
WinForm
关于CefSharp获取后的资源、截取request参数、拦截response数据、注入jquery文件和js代码
c#
Winform
问财数据获取源码(包括v值获取)
同花顺问财v值获取(hexin-v),获取后可通过get/
post
方式
获取问财数据 目前只能获取某个条件搜索出来的前50条数据。可以添加多个搜索条件。 项目含搜索数据展示,过滤,excel保存等。
winform
客户端发送
POST
请求
调用API接口传递参数
API接受
POST
请求
,
C# 网络
Http
请求
Get与
Post
提示:以下是本篇文章正文
内容
,下面案例可供参考 1.引入库 代码如下(示例): using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System.Collections.Generic; using System.Net.
Http
; using System.Net.
Http
.Headers; Get
请求
代码如下(示例): /// <summary> ///
Http
Get方法 /// </summary> ///.
解决
post
请求
无法获取到值的问题
那是因为流对应的是数据,数据放在内存
中
,有的是部分放在内存
中
。上面这篇博客
中
提到了解决方案,就是重写
Http
ServletRequestWrapper把request保存下来,然后通过过滤器把保存下来的request再填充进去,这样就可以多次读取request了。原因是request.getParamers(String) 方法获取
post
请求
时,需要确保
请求
头
中
设置了正确的 Content-Type,例如。,如果在拦截器
中
被读取了,那么在@RequestBody时是会报错的。④记得在启动类
中
注册拦截器。
C#
110,545
社区成员
642,580
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章