zoukankan
html css js c++ java
与采集有关的两个小函数
private
static
string
PostData(
string
url,
string
postdata, CookieContainer cookieContainer)
{
string
outdata
=
string
.Empty;
HttpWebRequest request
=
(HttpWebRequest)WebRequest.Create(url);
request.ContentType
=
"
application/x-www-form-urlencoded
"
;
request.ContentLength
=
postdata.Length;
request.UserAgent
=
userAgent;
request.Method
=
"
POST
"
;
request.CookieContainer
=
cookieContainer;
using
(Stream inStream
=
request.GetRequestStream())
{
using
(StreamWriter sw
=
new
StreamWriter(inStream, Encoding.GetEncoding(
"
gb2312
"
)))
{
sw.Write(postdata);
}
}
HttpWebResponse response
=
(HttpWebResponse)request.GetResponse();
response.Cookies
=
cookieContainer.GetCookies(request.RequestUri);
using
(Stream outStream
=
response.GetResponseStream())
{
using
(StreamReader sr
=
new
StreamReader(outStream, Encoding.GetEncoding(
"
gb2312
"
)))
{
outdata
=
sr.ReadToEnd();
}
}
return
outdata;
}
private
static
string
GetDate(
string
url, CookieContainer myCookieContainer)
{
HttpWebRequest request
=
(HttpWebRequest)WebRequest.Create(url);
request.ContentType
=
"
text/html
"
;
request.Method
=
"
GET
"
;
request.CookieContainer
=
myCookieContainer;
HttpWebResponse response
=
(HttpWebResponse)request.GetResponse();
string
outdata
=
string
.Empty;
if
(request.HaveResponse)
{
foreach
(Cookie returnCookie
in
response.Cookies)
{
bool
cookieFound
=
false
;
foreach
(Cookie oldCookie
in
myCookieContainer.GetCookies(request.RequestUri))
{
if
(returnCookie.Name.Equals(oldCookie.Name))
{
oldCookie.Value
=
returnCookie.Value;
cookieFound
=
true
;
}
}
if
(
!
cookieFound)
myCookieContainer.Add(returnCookie);
}
}
using
(Stream outStream
=
response.GetResponseStream())
{
using
(StreamReader sr
=
new
StreamReader(outStream, Encoding.GetEncoding(
"
gb2312
"
)))
{
outdata
=
sr.ReadToEnd();
}
}
return
outdata;
}
查看全文
相关阅读:
oracle 12C linux centos7.5 安装 12C
FizzBuzz
批量判断能否telnet登录
统计所有机器的挂载情况
ffmpeg windows vs library 下载地址
需求文档测试
接口测试分析
chrome网页截图
不要为了测试写一个新系统
C# 判断是否为数字
原文地址:https://www.cnblogs.com/afxcn/p/775945.html
最新文章
流畅的python——15 上下文管理器和 else 块
流畅的python——12 继承的优缺点
elasticsearch——入门
HTTP三次握手、四次挥手
线程切换
Object 默认方法
Java IO 常见类
mybatis
循环依赖解决思路
4核8G
热门文章
js 常用创建a标签实现下载功能
东吴证券张之浩:从理论到落地的 DevOps 体系建设
FabEdge 与 OpenYurt 集成验证——云边数据面通信初试
无锡农商行王宗:敏态转型,实现科技引领业务的华丽转身
做好ssh远程访问安全
js 处理日期加减
配色网站
学习如何高效率编写单片机代码,优化程序设计
学习单片机程序框架
MongoDB 4.4 安装 linux
Copyright © 2011-2022 走看看