简体   繁体   English

Fiddler没有从Java应用程序捕获HTTP请求

[英]Fiddler not capturing HTTP requests from Java Application

I am currently writing a java application that uses HTTP POST to upload a csv file and a few other parameters to a server. 我目前正在编写一个使用HTTP POST将csv文件和一些其他参数上传到服务器的java应用程序。 The server keeps returning 500 errors to my application and I would like to view the HTTP request in Fiddler so I can see the POST request. 服务器不断向我的应用程序返回500个错误,我想在Fiddler中查看HTTP请求,以便我可以看到POST请求。
When I run Fiddler it will not capture any HTTP traffic from the Java application. 当我运行Fiddler时,它不会捕获来自Java应用程序的任何HTTP流量。 I have written a GET request that works, so I know I can communicate with the server, however no traffic is shown through Fiddler. 我写了一个有效的GET请求,所以我知道我可以与服务器通信,但是没有通过Fiddler显示流量。

You can simply set Fiddler as HTTP proxy for your application by setting the properties 您可以通过设置属性将Fiddler设置为应用程序的HTTP代理

http.proxyHost to localhost and http.proxyPort to 8888 for HTTP traffic and https.proxyHost / https.proxyPort for HTTPS traffic. 对于HTTP流量, http.proxyHostlocalhosthttp.proxyPort8888 ,对于HTTPS流量为https.proxyHost / https.proxyPort For HTTPS traffic you also have to add the Fiddler root certificate (exportable in options dialog) as trusted certificate to your application. 对于HTTPS流量,您还必须将Fiddler根证书(可在选项对话框中导出)作为可信证书添加到您的应用程序。

You can do so by adding the following lines at the beginning of your code 您可以通过在代码开头添加以下行来完成此操作

System.setProperty("http.proxyHost", "localhost");
System.setProperty("http.proxyPort", "8888");

or set them via command line when starting the Java-VM: 或者在启动Java-VM时通过命令行设置它们:

java -Dhttp.proxyHost=localhost -Dhttp.proxyPort=8888 ...

With Jetty HTTP client, the previous solution doesn't work. 使用Jetty HTTP客户端,以前的解决方案不起作用。 The following works however: 但是以下工作:

HttpClient httpClient = new HttpClient();
httpClient.setProxy(new Address("127.0.0.1", 8888));
httpClient.start();

使用EasyRestClient使用此:

ClientBuilder builder = new ResteasyClientBuilder().defaultProxy("localhost", 8888, "http");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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