我需要使用spring-social向twitter发送请求。应用程序从tomcat中的war运行。
请求应由ConnectionControler.class
重定向:
@RequestMapping(value="/{providerId}", method=RequestMethod.POST)
public RedirectView connect(@PathVariable String providerId, NativeWebRequest request) {
ConnectionFactory<?> connectionFactory = connectionFactoryLocator.getConnectionFactory(providerId);
MultiValueMap<String, String> parameters = new LinkedMultiValueMap<String, String>();
preConnect(connectionFactory, parameters, request);
try {
return new RedirectView(connectSupport.buildOAuthUrl(connectionFactory, request, parameters));
} catch (Exception e) {
sessionStrategy.setAttribute(request, PROVIDER_ERROR_ATTRIBUTE, e);
return connectionStatusRedirect(providerId, request);
}
}
我得到org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://api.twitter.com/oauth/request_token": Connection refused; nested exception is java.net.ConnectException: Connection refused
同样的问题出现在另一个基于spring-boot的应用程序中,问题通过添加VM参数解决了
-Dhttp.proxyPort=9050
-Dhttp.proxyHost=192.168.10.10
-Dhttps.proxyPort=9050
-Dhttps.proxyHost=192.168.10.10
但是对于在tomcat中从war运行的应用程序,它不起作用。此外,我尝试以编程方式设置参数,这通常是相同的,当spring spring initialize context:
System.setProperty( "http.proxyPort", "9050" );
System.setProperty( "https.proxyPort", "9050" );
System.setProperty( "http.proxyHost", "192.168.10.10" );
System.setProperty( "https.proxyHost", "192.168.10.10" );