当前位置: 代码迷 >> 综合 >> Content-Type cannot contain wildcard type ‘*‘
  详细解决方案

Content-Type cannot contain wildcard type ‘*‘

热度:35   发布时间:2023-12-18 04:01:56.0

使用RestTemplate调用https请求报此错误 需修改一下https协议

RestTemplate restTemplate = new RestTemplate(new HttpsClientRequestFactory());

public class HttpsClientRequestFactory extends SimpleClientHttpRequestFactory {@Overrideprotected void prepareConnection(HttpURLConnection connection, String httpMethod) {try {if (!(connection instanceof HttpsURLConnection)) {// http协议// throw new RuntimeException("An instance of HttpsURLConnection is expected");super.prepareConnection(connection, httpMethod);}if (connection instanceof HttpsURLConnection) {// https协议,修改协议版本KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());// 信任任何链接TrustStrategy anyTrustStrategy = new TrustStrategy() {@Overridepublic boolean isTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {return true;}};SSLContext ctx = SSLContexts.custom().useTLS().loadTrustMaterial(trustStore, anyTrustStrategy).build();((HttpsURLConnection)connection).setSSLSocketFactory(ctx.getSocketFactory());HttpsURLConnection httpsConnection = (HttpsURLConnection)connection;super.prepareConnection(httpsConnection, httpMethod);}} catch (Exception e) {e.printStackTrace();}}}

  相关解决方案