eclipse - 配置 Eclipse 以允许 Fiddler 拦截请求

标签 eclipse fiddler

在 Eclipse 中,我尝试配置了两个地方,以便 Fiddler 可以拦截我发送的 HTTP/HTTPS 请求:

  • Windows > Preference > General > Network Connections - 我试过原生/直接/手动
  • 在 VM 参数中,我添加以下 -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);
    
  • 使用“标准JRE代理选择器获取代理信息”

    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/

    相关文章:

    android - 拦截来自安卓应用的流量

    java - 无法获取 Windows ProductId key ,但可以获取 ProductName key

    java - Fiddler java https - "unable to find valid certification path to requested target"

    c# - 过滤fiddler以仅捕获特定域的请求

    java - Eclipse Rcp 在整个应用程序启动并且 GUI 完全呈现后运行基于 E4 的代码

    http-post - 使用 Fiddler 检查 POST 请求

    fiddler - 使用 Fiddler 作为反向代理

    c++ - 替代 Eclipse 进行 C 和 C++ 开发?

    android - Eclipse 连接到存储库并在 Windows 8 上安装 ADT 插件时出错

    android - 如何在单击按钮时刷新 fragment 选项卡内容