|
10 | 10 | import org.apache.http.impl.client.CloseableHttpClient;
|
11 | 11 | import org.apache.http.impl.client.HttpClients;
|
12 | 12 | import org.apache.http.util.EntityUtils;
|
13 |
| -import org.junit.Ignore; |
14 | 13 | import org.junit.Test;
|
15 | 14 | import us.codecraft.webmagic.Page;
|
16 | 15 | import us.codecraft.webmagic.Request;
|
@@ -255,15 +254,21 @@ public void run() throws Exception {
|
255 | 254 | });
|
256 | 255 | }
|
257 | 256 |
|
258 |
| - @Ignore("need proxy server") |
259 | 257 | @Test
|
260 |
| - public void test_download_by_SimpleProxyProvider(){ |
261 |
| - HttpClientDownloader httpClientDownloader = new HttpClientDownloader(); |
262 |
| - httpClientDownloader.setProxyProvider(SimpleProxyProvider.from(new Proxy("127.0.0.1", 1087))); |
263 |
| - Request request = new Request(); |
264 |
| - request.setUrl("https://www.baidu.com"); |
265 |
| - Page page = httpClientDownloader.download(request, Site.me().toTask()); |
266 |
| - assertThat(page.isDownloadSuccess()); |
| 258 | + public void test_download_auth_by_SimpleProxyProvider() throws Exception { |
| 259 | + HttpServer server = httpServer(13423); |
| 260 | + server.get(eq(header("Proxy-Authorization"), "Basic dXNlcm5hbWU6cGFzc3dvcmQ=")).response("ok"); |
| 261 | + Runner.running(server, new Runnable() { |
| 262 | + @Override |
| 263 | + public void run() throws Exception { |
| 264 | + HttpClientDownloader httpClientDownloader = new HttpClientDownloader(); |
| 265 | + httpClientDownloader.setProxyProvider(SimpleProxyProvider.from(new Proxy("127.0.0.1", 13423, "username", "password"))); |
| 266 | + Request request = new Request(); |
| 267 | + request.setUrl("http://www.baidu.com"); |
| 268 | + Page page = httpClientDownloader.download(request, Site.me().toTask()); |
| 269 | + assertThat(page.getRawText()).isEqualTo("ok"); |
| 270 | + } |
| 271 | + }); |
267 | 272 | }
|
268 | 273 |
|
269 | 274 | }
|
0 commit comments