简体   繁体   English

如何在 Pac4j-oauth 中使用 HTTP 代理?

[英]How to use HTTP Proxy with Pac4j-oauth?

Recently I'm using pac4j project for Oauth Twitter.Running on the local, everything works fine.But when I'm running on the remote server, unfortunately, the service doesn't work properly because there is no direct access to the external.network.最近我正在为 Oauth Twitter 使用 pac4j 项目。在本地运行,一切正常。但是当我在远程服务器上运行时,不幸的是,该服务无法正常工作,因为无法直接访问外部。网络。

For example,in apache.httpcomponents:httpclient:比如apache.httpcomponents:httpclient:

HttpClients.custom().setSSLSocketFactory(sslsf).setProxy(new HttpHost("192.168.200.14", 8080)).build()

How to use HTTP Proxy with Pac4j-oauth?如何在 Pac4j-oauth 中使用 HTTP 代理?

You should be able to do:你应该能够做到:

JDKHttpClientConfig myConfig = JDKHttpClientConfig.defaultConfig();

Proxy myProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("1.0.0.0", 8080));
myConfig.setProxy(myProxy);

twitterClient.getConfiguration().setHttpClientConfig(myConfig);

OK.I had a new idea when I saw scribejava in github OK,在github看到scribejava我有了新的想法

pom.xml needs to be added: pom.xml 需要添加:

<groupId>com.github.scribejava</groupId>
<artifactId>scribejava-httpclient-apache</artifactId>

code needs to be added:需要添加代码:

//use Http Proxy
final HttpClientConfig clientConfig = new ApacheHttpClientConfig(HttpAsyncClientBuilder.create()
                .setProxy(new HttpHost("1.0.0.0", 8080)));
twitterClient.getConfiguration().setHttpClientConfig(clientConfig);

Finally worked fine when I tested with this scheme.当我用这个方案测试时,终于工作得很好。

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

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