Charles 没有在我的 MAC pro 中捕获来自 Java 客户端(客户端基于 Spring Rest 模板)的 HTTP 请求

Cod*_*der 5 proxy http fiddler webproxy charles-proxy

环境:MAC进程

我研究了使用 MonoTouch、HttpClient 和 Charles Proxy 时的 HTTP 流量监控问题

虽然我的问题与之类似,但我的应用程序正在使用RestTemplate http://docs.spring.io/autorepo/docs/spring-android/1.0.x/reference/html/rest-template.html。每当请求通过网络浏览器(具体来说是 Safari 和 Chrome)时,我都能够捕获 HTTP 和 HTTPS 流量,而当我通过我的应用程序(基本上使用 RestTemplate)发出休息请求时,Charles 代理不会捕获它们。

从上述问题的答案来看,应该是与RestTempate上的代理设置有关。但我是一名 .NET 开发人员,对 fiddler 非常熟悉 - 但最近转向 Java,对 Charles 还很陌生 - 因此,如果您能让我知道具体细节,或者您对配置 REST 模板以使用我的 macOS 代理的想法,那就太好了。 ..

基本上问题是如何配置我的休息模板(客户端),以便 charles Web 代理能够通过我的应用程序(客户端)捕获请求和响应。

其余模板由扩展 __https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/http/client/ SimpleClientHttpRequestFactory .html 的自定义请求工厂实例化。


看起来我需要做类似的事情(参考:http://docs.spring.io/spring-integration/reference/html/http.html#http-proxy

<bean id="requestFactory"
    class="org.springframework.http.client.SimpleClientHttpRequestFactory">
    <property name="proxy">
        <bean id="proxy" class="java.net.Proxy">
            <constructor-arg>
                <util:constant static-field="java.net.Proxy.Type.HTTP"/>
            </constructor-arg>
            <constructor-arg>
                <bean class="java.net.InetSocketAddress">
                    <constructor-arg value="123.0.0.1"/>
                    <constructor-arg value="8080"/>
                </bean>
            </constructor-arg>
        </bean>
    </property>
</bean>
Run Code Online (Sandbox Code Playgroud)

anu*_*bhs 3

我也有类似的问题。但我使用的是 JUnit 和核心 Java。下面的链接在一些情况下对我有帮助。

\n\n

https://www.charlesproxy.com/documentation/configuration/browser-and-system-configuration/

\n\n

你可以去JAVA应用程序代理配置中寻找答案。

\n\n
\n

您可以将 Java 应用程序配置为在代码中使用 Charles 或作为 java 可执行文件的命令行参数。

\n\n
\n

System.setProperty("http.proxyHost", "127.0.0.1");

\n\n

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

\n
\n\n

对于 HTTPS 也是如此。请注意,在这种情况下,您可能还需要配置 Java\n 以信任 Charles\xe2\x80\x99s 根证书(请参阅 SSL 代理)。

\n
\n