Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
配置Eclipse以允许Fiddler拦截请求_Eclipse_Fiddler - Fatal编程技术网

配置Eclipse以允许Fiddler拦截请求

配置Eclipse以允许Fiddler拦截请求,eclipse,fiddler,Eclipse,Fiddler,在Eclipse中,我尝试配置两个地方,以便Fiddler能够截获我发出的HTTP/HTTPS请求: Windows>Preference>General>networkconnections-我试过原生/直接/手动 在VM参数中,我添加了以下-DproxySet=true-DproxyHost=127.0.0.1-DproxyPort=8888 编辑:我也尝试了rgerganov建议的新属性 我没有在Fiddler中接触任何与“网络”相关的设置,我已经将其设置为监视所有进程 我尝试使用Wire

在Eclipse中,我尝试配置两个地方,以便Fiddler能够截获我发出的HTTP/HTTPS请求:

  • Windows>Preference>General>networkconnections
    -我试过原生/直接/手动
  • 在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();
        }
      }
    
    publicstaticvoiddopost(){
    字符串post_url=”https://lookup.mxtelecom.com/USLookup";
    HttpParams params=新的BasicHttpParams();
    HttpProtocolParams.setVersion(params,HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(参数,“UTF-8”);
    HttpProtocolParams.setUseExpectContinue(params,true);
    SchemeRegistry supportedSchemes=新SchemeRegistry();
    注册(新方案(“https”,SSLSocketFactory.getSocketFactory(),443));
    register(新方案(“http”,PlainSocketFactory.getSocketFactory(),80));
    ClientConnectionManager ccm=新的ThreadSafeClientConnManager(参数,支持的方案);
    HttpClient m_Client=新的默认HttpClient(ccm,参数);
    HttpPost HttpPost=新的HttpPost(post_url);
    List postParameters=new ArrayList();
    添加(新的BasicNameValuePair(“某物”,“有用”);
    ResponseHandler ResponseHandler=新ResponseHandler(){
    @凌驾
    公共字符串HandlerResponse(HttpResponse响应)抛出ClientProtocolException,IOException{
    if(response.getEntity()!=null){
    返回EntityUtils.toString(response.getEntity());
    }
    返回null;
    }
    };
    试一试{
    UrlEncodedFormEntity实体=新的UrlEncodedFormEntity(后参数,“UTF-8”);
    httpPost.setEntity(实体);
    结果=m_Client.execute(httpPost、responseHandler);
    }捕获(客户端协议例外e){
    e、 printStackTrace();
    }捕获(IOE异常){
    e、 printStackTrace();
    }
    }
    
    Eclipse构建id:20100218-1602//3.5.2.R35x
    Fiddler2 v2.3.2.6
    jdk1.6.0_21


    如果您需要任何其他信息,请告诉我。

    第二种方法应该可以使用,但是属性是
    http.proxyHost
    http.proxyPort

    您可以在java中配置代理:

  • 使用系统属性
    • 通过VM参数(假设您希望为http和https流量启用代理):
  • java-Dhttp.proxyHost=127.0.0.1-Dhttp.proxyPort=8888-Dhttps.proxyHost=127.0.0.1-Dhttps.proxyPort=8888

    • 通过系统属性:

      // Get system properties
      Properties sysProperties = System.getProperties();
      // Specify proxy settings
      sysProperties.put("https.proxyHost", "127.0.0.1");
      sysProperties.put("https.proxyPort", "8888");
      sysProperties.put("http.proxyHost", "127.0.0.1");
      sysProperties.put("http.proxyPort", "8889");   
      
    此方法的“缺点”:一旦为协议设置了代理,该协议的所有连接都将使用代理

  • java.net.Proxy:从java 1.5开始提供。允许您指定用于打开连接的代理配置

    SocketAddress addr = new  InetSocketAddress("127.0.0.1", 8888);
    Proxy proxy = new Proxy(Proxy.Type.HTTP, addr);
    URL url = new URL("http://stackoverflow.com/");
    InputStream in = url.openConnection(proxy).getInputStream();
    
  • ProxySelector类:从Java 1.5开始提供。允许您按URI选择代理!它是一个抽象类,是一个简单的实现,返回所有http和https连接的代理,如下所示:

    public static class MyProxySelector extends ProxySelector {
        private List<Proxy> proxy;
        private List<Proxy> noProxy;
    
        MyProxySelector() {
            proxy = new ArrayList<Proxy>();
            SocketAddress addr = new  InetSocketAddress("127.0.0.1", 8888);
            proxy.add(new Proxy(Proxy.Type.HTTP, addr));
    
            noProxy = new ArrayList<Proxy>();
            noProxy.add(Proxy.NO_PROXY);
        }
    
        public List<Proxy> select(URI uri) {
            System.err.println("Connection to the proxy for uri :"+uri);
            if (uri == null) {
                throw new IllegalArgumentException("URI can't be null.");
            }
            String protocol = uri.getScheme();
    
            if ("http".equalsIgnoreCase(protocol) || "https".equalsIgnoreCase(protocol)) {
                //if http or https connection, return our proxy config
                return proxy;
            } else {
                // Otherwise don't use a proxy
                return noProxy;
            }
        }
    
        @Override
        public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
            System.err.println("Connection to the proxy failed !");
            //throw exception or do some stuff...
        }
    }
    
    我更喜欢最后一种机制,因为您可以进行一些日志记录,看看Java在做什么

    重要提示: 默认情况下,Fiddler只捕获来自web浏览器的流量!!更改此选项以捕获所有进程的流量:

    (来源:)

    HttpClient
    需要了解代理信息。可以使用几种方法:

    请参见HTTP组件中的2.7:

  • “通过代理连接到目标主机是通过设置默认代理参数”

    DefaultHttpClient-httpclient=newdefaulthttpclient();
    HttpHost代理=新的HttpHost(“127.0.0.1”,8888);
    httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,PROXY);
    
  • 使用“标准JRE代理选择器获取代理信息”

    DefaultHttpClient-httpclient=newdefaulthttpclient();
    ProxySelectorRoutePlanner routePlanner=新建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
    实现(我没有探索这个选项)


  • 此外,在Fiddler中,如果需要从HTTPS连接捕获所有进程,则需要转到工具菜单-Fiddler选项-HTTPS-检查“解密HTTPS流量”并选择“…来自所有进程”


    从Fiddler的状态栏中选择“所有进程”显然只用于HTTP连接。

    可以使用代理主机和代理端口的JVM参数。同时,需要安装Fiddler证书来嗅探https连接。

    谢谢,我检查了,这些肯定是要使用的属性,但不幸的是,Fiddler2中没有显示任何内容。更深入地说:谢谢,这无疑是朝着正确的方向迈出的一大步。我做了检查以确保Fiddler检查了“所有进程”。您的ProxySelector让我在Apache的HTTPComponent文档中进一步思考和查找,我确实发现了与您提供的代码类似的代码,并且它可以正常工作。我没有提到连接是如何建立的,这使得回答这个问题变得非常困难-jdramix的答案是
        public static void main(String[] args){
         ProxySelector.setDefault(new MyProxySelector());
         //...
        }