Tag: apache httpclient 4.x

Apache httpcomponent返回java.net.UnknownHostException:名称或服务未知

我试图使用Apache Httpcomponents 4.5.1在Instagram上进行oauthlogin,但是无法成功获取访问令牌。 我很确定这是库本身的问题,因为如果我curl,我会得到我想要的结果。 所以,我尝试了几种不同的方式来完成后调用,但是他们都给了我相同的结果,所以我只是发布我find的最优雅的方式是使用fluent-hc库: @Value("${instagram.client.id}") private String clientID; @Value("${instagram.client.secret}") private String clientSecret; @Value("${instagram.redirect.uri}") private String redirectURI; private static final String INSTAGRAM_ACCESS_TOKEN_URL = "https://api.instagram.com/oauth/access_token"; private Content requestAccessToken(String code, UserType userType) throws IOException { // String authorization_header_string = URLEncoder.encode(clientID + ":" + clientSecret, "UTF-8"); return Request.Post(INSTAGRAM_ACCESS_TOKEN_URL) .bodyForm(Form.form() .add("client_id", clientID) .add("client_secret", clientSecret) .add("grant_type", "authorization_code") .add("redirect_uri", redirectURI + […]