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;
}
查看全文
相关阅读:
面向使用的软件设计随笔13
面向使用的软件设计随笔12
面向使用的软件设计随笔11
面向使用的软件设计随笔10
面向使用的软件设计随笔09
面向使用的软件设计随笔08
面向使用的软件设计随笔07
Tensorflow入门----占位符、常量和Session
关于卷积
tensorflow学习笔记
原文地址:https://www.cnblogs.com/afxcn/p/775945.html
最新文章
关于Ruby的一些知识
Ruby Hash与ActiveSupport’s HashWithIndifferentAccess对于key的区别
NodeJS中form上传附件中针对表单的multiple attribute出现的问题总结
Linux查看系统状态命令
Linux压力测试工具
GIT用法总结
Ubuntu 12.04安装Google Chrome
[MySQL]
PHP单线程和多线程调用
45种Javascript技巧大全
热门文章
阻止jQuery事件冒泡
HTTP Caching 优化网站
Web 前端性能优化【转】
WEB前端性能分析--工具篇【转】
网站前端性能优化总结【转】
<span>标签内容超出进行换行
javascript获取url参数方法
面向使用的软件设计随笔16
面向使用的软件设计随笔15
面向使用的软件设计随笔14
Copyright © 2011-2022 走看看