在 Eclipse 中,我尝试配置了两个地方,以便 Fiddler 可以拦截我发送的 HTTP/HTTPS 请求:
Windows > Preference > General > Network Connections
- 我试过原生/直接/手动-DproxySet=true -DproxyHost=127.0.0.1 -DproxyPort=8888
编辑:我也尝试过 rgerganov 建议的新属性。
我没有在 Fiddler 中触及任何与“网络”相关的设置,我已经将它设置为监视所有进程。
我尝试使用 Wireshark,我能够在不修改 Eclipse 的情况下拦截请求,但是 Wireshark 中提供的信息太深入了,我不需要 Wireshark 提供的大部分细节。
编辑:这是我正在尝试的示例代码:
public static void doPOST() {
String post_url = "https://lookup.mxtelecom.com/USLookup";
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion( params, HttpVersion.HTTP_1_1 );
HttpProtocolParams.setContentCharset( params, "UTF-8" );
HttpProtocolParams.setUseExpectContinue( params, true );
SchemeRegistry supportedSchemes = new SchemeRegistry();
supportedSchemes.register( new Scheme( "https", SSLSocketFactory.getSocketFactory(), 443 ) );
supportedSchemes.register( new Scheme( "http", PlainSocketFactory.getSocketFactory(), 80 ) );
ClientConnectionManager ccm = new ThreadSafeClientConnManager( params, supportedSchemes );
HttpClient m_Client = new DefaultHttpClient( ccm, params );
HttpPost httpPost = new HttpPost( post_url );
List<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add( new BasicNameValuePair( "something", "useful" ) );
ResponseHandler<String> responseHandler = new ResponseHandler<String>() {
@Override
public String handleResponse( HttpResponse response ) throws ClientProtocolException, IOException {
if ( response.getEntity() != null ) {
return EntityUtils.toString( response.getEntity() );
}
return null;
}
};
try {
UrlEncodedFormEntity entity = new UrlEncodedFormEntity( postParameters, "UTF-8" );
httpPost.setEntity( entity );
results = m_Client.execute( httpPost, responseHandler );
} catch ( ClientProtocolException e ) {
e.printStackTrace();
} catch ( IOException e ) {
e.printStackTrace();
}
}
Eclipse 构建 ID:20100218-1602//3.5.2.R35x
Fiddler2 v2.3.2.6
jdk1.6.0_21
如果您需要任何其他信息,请告诉我。
最佳答案
HttpClient
需要知道代理信息。可以使用几种方法:
参见 HTTP 组件的 documentation 中的 2.7 :
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpHost proxy = new HttpHost("127.0.0.1", 8888);
httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
DefaultHttpClient httpclient = new DefaultHttpClient();
ProxySelectorRoutePlanner routePlanner = new ProxySelectorRoutePlanner(
httpclient.getConnectionManager().getSchemeRegistry(), ProxySelector.getDefault());
httpclient.setRoutePlanner(routePlanner);
然后将以下内容添加为 VM 参数:
-Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=8888 -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=8888
RoutePlanner
实现(我没有探索这个选项)关于eclipse - 配置 Eclipse 以允许 Fiddler 拦截请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5302476/