Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Page MenuHomePhabricator
Paste P3219

MerlBot-proxy test
ActivePublic

Authored by bd808 on Jun 8 2016, 1:20 AM.
Tags
None
Referenced Files
F4141349: MerlBot-proxy test
Jun 8 2016, 1:20 AM
Subscribers
None
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* @author Bryan Davis <bd808@wikimedia.org>
* @copyright 2016 Bryan Davis and Wikimedia Foundation. All Rights Reserved.
* @license Apache-2.0
*/
public class ProxyTest {
public static void main(String[] args) throws Exception {
URL url = new URL("http://en.wikipedia.org/w/api.php");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("User-Agent", "bd808 testing MerlBot proxy");
conn.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
wr.writeBytes("action=query&meta=tokens&type=login&format=json");
wr.flush();
wr.close();
int responseCode = conn.getResponseCode();
System.out.println("\nSending 'POST' request to URL : " + url);
System.out.println("Response Code : " + responseCode);
Map<String, List<String>> hdrs = conn.getHeaderFields();
Set<String> hdrKeys = hdrs.keySet();
for (String k : hdrKeys) {
System.out.println(k + ": " + hdrs.get(k));
}
BufferedReader in = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine);
}
in.close();
}
}

Event Timeline

$ javac ProxyTest.java
$ java -Dhttp.proxyHost=127.0.0.1 -Dhttp.ProxyPort=80 ProxyTest

Sending 'POST' request to URL : http://en.wikipedia.org/w/api.php
Response Code : 200
null: [HTTP/1.1 200 OK]
Age: [0]
Cache-control: [private, must-revalidate, max-age=0]
Backend-Timing: [D=38033 t=1465348859759426]
X-Client-IP: [10.68.17.97]
Set-Cookie: [GeoIP=:::::v4; Path=/; secure; Domain=.wikipedia.org, WMF-Last-Access=08-Jun-2016;Path=/;HttpOnly;secure;Expires=Sun, 10 Jul 2016 00:00:00 GMT, forceHTTPS=true; path=/; httponly, enwikiSession=v29ljp6j1j5pn033kn33iu60vpq85baf; path=/; secure; httponly]
Connection: [keep-alive]
Server: [nginx/1.4.6 (Ubuntu)]
X-Powered-By: [HHVM/3.12.1]
X-Cache: [cp1055 pass, cp1052 pass]
X-Content-Type-Options: [nosniff]
X-Frame-Options: [SAMEORIGIN]
X-Varnish: [3353490644, 3474027913]
Strict-Transport-Security: [max-age=31536000; includeSubDomains; preload]
Vary: [Accept-Encoding]
Labs-TLS-Bandaid: [on]
Transfer-Encoding: [chunked]
Date: [Wed, 08 Jun 2016 01:20:59 GMT]
P3P: [CP="This is not a P3P policy! See https://en.wikipedia.org/wiki/Special:CentralAutoLogin/P3P for more info."]
X-Analytics: [https=1;nocookies=1]
Via: [1.1 varnish, 1.1 varnish]
Content-Type: [application/json; charset=utf-8]
{"batchcomplete":"","query":{"tokens":{"logintoken":"7b0865c1b83517584802c1c16f11a1c5575772fb+\\"}}}