简体   繁体   中英

BrowserMob Proxy - The remote server returned an error: (404) Not Found

I'm trying to use BrowserMob Proxy with Selenium in C#.

I've tried this solution here: http://www.adathedev.co.uk/2012/02/automating-web-performance-stats.html

And my code looks like this:

Server server = new Server(@"path_to\\browsermob-proxy.bat");
server.Start();
Client client = server.CreateProxy();
client.NewHar("test");

var seleniumProxy = new Proxy { HttpProxy = client.SeleniumProxy };
var profile = new FirefoxProfile();

profile.SetProxyPreferences(seleniumProxy);
IWebDriver driver = new FirefoxDriver(profile);

When I run the test I get the following error:

System.Net.WebException: The remote server returned an error: (404) Not Found.

It fails at the third line.

Any suggestions on how to get this working?

If you can post a more detailed stack trace, that would be useful, along with the remote host you're trying to connect to. In the meantime a few things to try are:

  • Check the address you're requesting. It seems you're getting a 404 -- can you hit it through a browser without the proxy?
  • Make sure browsermob-proxy.bat is installed at the path on line 1 (is it really in a subdirectory of the working directory called "path_to"?)
  • Check your write permissions in the temp directory, which is %TEMP% or %TMP% on Windows. BMP writes temporary files there.
  • Grab the latest source and build the .bat file. The instructions are on the browsermob-proxy github page at the bottom (under Creating the batch files from source ).

Hope that helps!

This is most likely because your Jetty service is not actually running, did you get a message from BrowserMob batch file saying it couldn't run? In my case it was a situation where the port (by default is set to 8080) but I had something else listening on that port. To fix this, you can pass an optional port number.

var server = new Server(@"C:\path\to\bin\browsermob-proxy.bat", 9090);

I had same problem on python. When I had tried to get content of localhost:8080 I got 404 error. It turned out that my other application was using same 8080 port. So I found PID typing in cmd: netstat -o -n -a | findstr :8080 netstat -o -n -a | findstr :8080 . Then I just terminated process with this PID and browsermob gave me well HAR.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM