Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
webmagic
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
沈俊林
webmagic
Commits
a37f40e6
Commit
a37f40e6
authored
Nov 03, 2013
by
yihua.huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add cookie supoort
parent
3c6fced4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
4 deletions
+7
-4
HttpClientDownloader.java
...s/codecraft/webmagic/downloader/HttpClientDownloader.java
+4
-2
HttpClientPool.java
...java/us/codecraft/webmagic/downloader/HttpClientPool.java
+3
-2
No files found.
webmagic-core/src/main/java/us/codecraft/webmagic/downloader/HttpClientDownloader.java
View file @
a37f40e6
...
@@ -3,6 +3,7 @@ package us.codecraft.webmagic.downloader;
...
@@ -3,6 +3,7 @@ package us.codecraft.webmagic.downloader;
import
com.google.common.collect.Sets
;
import
com.google.common.collect.Sets
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.annotation.ThreadSafe
;
import
org.apache.http.annotation.ThreadSafe
;
import
org.apache.http.client.config.CookieSpecs
;
import
org.apache.http.client.config.RequestConfig
;
import
org.apache.http.client.config.RequestConfig
;
import
org.apache.http.client.methods.CloseableHttpResponse
;
import
org.apache.http.client.methods.CloseableHttpResponse
;
import
org.apache.http.client.methods.RequestBuilder
;
import
org.apache.http.client.methods.RequestBuilder
;
...
@@ -102,8 +103,9 @@ public class HttpClientDownloader implements Downloader {
...
@@ -102,8 +103,9 @@ public class HttpClientDownloader implements Downloader {
}
}
RequestConfig
.
Builder
requestConfigBuilder
=
RequestConfig
.
custom
()
RequestConfig
.
Builder
requestConfigBuilder
=
RequestConfig
.
custom
()
.
setConnectionRequestTimeout
(
site
.
getTimeOut
())
.
setConnectionRequestTimeout
(
site
.
getTimeOut
())
.
setConnectTimeout
(
site
.
getTimeOut
());
.
setConnectTimeout
(
site
.
getTimeOut
())
if
(
site
.
getHttpProxy
()!=
null
){
.
setCookieSpec
(
CookieSpecs
.
BEST_MATCH
);
if
(
site
.
getHttpProxy
()
!=
null
)
{
requestConfigBuilder
.
setProxy
(
site
.
getHttpProxy
());
requestConfigBuilder
.
setProxy
(
site
.
getHttpProxy
());
}
}
requestBuilder
.
setConfig
(
requestConfigBuilder
.
build
());
requestBuilder
.
setConfig
(
requestConfigBuilder
.
build
());
...
...
webmagic-core/src/main/java/us/codecraft/webmagic/downloader/HttpClientPool.java
View file @
a37f40e6
...
@@ -81,10 +81,11 @@ public class HttpClientPool {
...
@@ -81,10 +81,11 @@ public class HttpClientPool {
if
(
site
!=
null
){
if
(
site
!=
null
){
httpClientBuilder
.
setRetryHandler
(
new
DefaultHttpRequestRetryHandler
(
site
.
getRetryTimes
(),
true
));
httpClientBuilder
.
setRetryHandler
(
new
DefaultHttpRequestRetryHandler
(
site
.
getRetryTimes
(),
true
));
}
}
generateCookie
(
httpClientBuilder
,
site
);
return
httpClientBuilder
.
build
();
return
httpClientBuilder
.
build
();
}
}
private
void
generateCookie
(
DefaultHttpClient
httpClient
,
Site
site
)
{
private
void
generateCookie
(
HttpClientBuilder
httpClientBuilder
,
Site
site
)
{
CookieStore
cookieStore
=
new
BasicCookieStore
();
CookieStore
cookieStore
=
new
BasicCookieStore
();
if
(
site
.
getCookies
()
!=
null
)
{
if
(
site
.
getCookies
()
!=
null
)
{
for
(
Map
.
Entry
<
String
,
String
>
cookieEntry
:
site
.
getCookies
().
entrySet
())
{
for
(
Map
.
Entry
<
String
,
String
>
cookieEntry
:
site
.
getCookies
().
entrySet
())
{
...
@@ -93,7 +94,7 @@ public class HttpClientPool {
...
@@ -93,7 +94,7 @@ public class HttpClientPool {
cookieStore
.
addCookie
(
cookie
);
cookieStore
.
addCookie
(
cookie
);
}
}
}
}
httpClient
.
se
tCookieStore
(
cookieStore
);
httpClient
Builder
.
setDefaul
tCookieStore
(
cookieStore
);
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment