Setting proxy hosts

1,071 views
Skip to first unread message

PRobbins

unread,
Feb 14, 2012, 5:44:28 PM2/14/12
to BrowserMob Proxy
Hey all,
I've been using browsermob-proxy with great results, but the one issue
that I've been having trouble with is using my host file to point the
proxy to the right place for certain URLs. Is there any easy way to
get the browsermob proxy to use the host settings from my local
machine in the proxy as well? I'd like to gather some HAR data from a
staging site but when I use the proxy the browser doesn't know what IP
to point to for the URL. Right now Im using port 8080 for the proxy.
Is there a local port that I can use instead? Or some other
solution? Thanks!

Patrick Lightbody

unread,
Mar 1, 2012, 2:42:03 AM3/1/12
to browserm...@googlegroups.com
It sounds like you just need to remap a host to a different IP address? If so, the proxy has a specific IP for doing that (remapHost). Have you tried it out? No need for hosts files at all if you use that.

--
Patrick Lightbody



Isaiah

unread,
Mar 16, 2012, 6:14:16 PM3/16/12
to BrowserMob Proxy
I also am having this problem. My issue is I have a load balancer at
www but need to hit a specific app server. I tried using the
remapHost function but not sure what order to place the strings in or
when I should call it. Also is is a specific match? So do I need to
put fully www.mysite.com or can I just do www and specify the IP I
want to hit?

Patrick Lightbody

unread,
Mar 23, 2012, 12:29:44 AM3/23/12
to browserm...@googlegroups.com
I assume you're using Java, since we don't have this capability exposed via the REST API yet. When in doubt, remember: "Use the source, Luke" :)

public void remapHost(String source, String target) {
client.remapHost(source, target);
}

So for example you can do:

ProxyServer p = new ProxyServer(9091);
p.remapHost("example.com", 1.2.3.4);

That will make any lookup to example.com bypass DNS and go to 1.2.3.4. Keep in mind that it *only* works for example.com, and not www.example.com or any other host.

Hope that helps!

--
Patrick Lightbody
+1 (415) 830-5488

Ramesh Jhajharia

unread,
Oct 22, 2012, 2:46:53 AM10/22/12
to browserm...@googlegroups.com
Hi Patrick ,

Do we have these API's and functions available for .Net also.

I also need same function and I am using selenium with C#.

Please help me.

Thanks,
Ramesh Jhajharia

Patrick Lightbody

unread,
Oct 22, 2012, 12:09:40 PM10/22/12
to browserm...@googlegroups.com
I believe there is a REST API to do this. Check the docs/source.

Ramesh Jhajharia

unread,
Oct 29, 2012, 6:43:07 AM10/29/12
to browserm...@googlegroups.com
Thanks Patrik,

I am using selenium web driver and Selenium webdrive have its own api's to navigate to URLs and if I will use rest API or HtteWebRequest methods then I won't be able to
instruct my Firefox driver to navigate to URL and remap the host.

If I am not clear then please paste some example code here which can help me.

Thanks Again.

Ramesh Jhajharia

unread,
Nov 6, 2012, 8:52:16 AM11/6/12
to browserm...@googlegroups.com
Hey ,

I tried with the REST API's also with C# .net and I found two thing :
1. Browser Mob is not working on specifying ports.
  Like if I specify a port at the time of creating server along with server path , I am getting 500 , internal server error.

2. I couldn't remapped the host using rest API's also.
I tried this using direct CURL requests after running the bowser mob.

Thanks,
Ramesh Jhajharia


On Wednesday, 15 February 2012 04:14:28 UTC+5:30, PRobbins wrote:

Krishnan Mahadevan

unread,
Nov 6, 2012, 9:44:43 AM11/6/12
to browserm...@googlegroups.com
Ramesh,
I was able to create a new proxy by specifying the port using the following method (REST API invocation via Java)

    public static String getProxy() throws ClientProtocolException, IOException{
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://localhost:9090/proxy");
        String reqStr = "port=9099";
        httppost.setEntity(new StringEntity(reqStr, "UTF-8"));
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        String response = httpclient.execute(httppost, responseHandler);
        httpclient.getConnectionManager().shutdown();
        return response;
    }


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
Reply all
Reply to author
Forward
0 new messages