Tag: httpclient

ASP核心HttpClient.Get从容器到本地主机的网站是失败的

鉴于: Windows 10 PC与Docker(Linux容器格式) IIS中的本地网站可以在裸机(无容器) http:// localhost / foo上访问 想要访问HTTP GET的http核心DockerContainer http:// localhost / foo 问题: 所有对http:// localhost的请求都失败 var client = new HttpClient(); var result = await client.GetAsync("http://localhost/foo"); 然后我得到 System.Net.Http.HttpRequestException:发送请求时发生错误。 —> System.Net.Http.CurlException:无法连接到服务器System.Net.Http.CurlHandler.ThrowIfCURLEError(CURLcode错误)在System.Net.Http.CurlHandler.MultiAge … 这是预期的吗? 我以为从容器内访问本地主机应该工作。 其他协议,如mongodb正在与本地主机。 所以它似乎是具体的http连接forms的ASP核心?

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 + […]

主机名称与主体提供的证书主题不匹配,但是完美匹配

我有两台服务器需要使用HTTPS相互通话。 在这种情况下,我们称之为“服务器”和“客户端”,其中“客户端正在对”服务器“进行https呼叫。 在生产中,服务器将具有有效的CA证书,但在testing时我们将使用自签名证书。 据我了解,这是我们必须做的: 创build证书 将其添加到服务器上的密钥库 将其添加到客户端上的受信任的cacerts密钥库(以便在尝试进行https调用时接受此自签名证书) 这一切都完成了,但是当打电话时,我得到这个错误: Caused by: javax.net.ssl.SSLPeerUnverifiedException: Host name 'docker-abc-123' does not match the certificate subject provided by the peer (CN=docker-abc-123, OU=unit, O=org, L=city, ST=area, C=xx) at org.apache.http.conn.ssl.SSLConnectionSocketFactory.verifyHostname(SSLConnectionSocketFactory.java:465) [httpclient-4.5.jar:4.5] at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:395) [httpclient-4.5.jar:4.5] at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:353) [httpclient-4.5.jar:4.5] at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:134) [httpclient-4.5.jar:4.5] at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353) [httpclient-4.5.jar:4.5] at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380) [httpclient-4.5.jar:4.5] at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236) [httpclient-4.5.jar:4.5] at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184) [httpclient-4.5.jar:4.5] at […]