国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

restTemplate轉(zhuǎn)發(fā)Https請求

這篇具有很好參考價(jià)值的文章主要介紹了restTemplate轉(zhuǎn)發(fā)Https請求。希望對大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

代碼架構(gòu)
restTemplate轉(zhuǎn)發(fā)Https請求

package com.http.controller;

import com.http.RestTemplateConfig;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping
public class httpControler {
    @RequestMapping(value = "two")
    public String two() {
        RestTemplate restTemplate = new RestTemplateConfig().restTemplate();
        String url = "https://www.baidu.com";
        ResponseEntity<String> res = restTemplate .getForEntity(url, String.class);
        return restTemplate.exchange(url, HttpMethod.GET, null, String.class).getBody();
    }
}

package com.http;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

@Configuration
public class RestTemplateConfig {
    @Bean
    public RestTemplate restTemplate() {
        HttpsClientRequestFactory factory = new HttpsClientRequestFactory();
        //單位為ms (部分接口數(shù)據(jù)量大,讀取改為60秒)
        factory.setReadTimeout(60000);
        //單位為ms
        factory.setConnectTimeout(10000);
        return new RestTemplate(factory);
    }
}
package com.http;

import org.apache.http.conn.ssl.TrustStrategy;
import org.apache.http.ssl.SSLContexts;
import org.springframework.http.client.SimpleClientHttpRequestFactory;

import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import java.net.HttpURLConnection;
import java.security.KeyStore;

/**
 * 繼承SimpleClientHttpRequestFactory 根據(jù)連接支持實(shí)現(xiàn)http和https請求發(fā)送
 */
public class HttpsClientRequestFactory extends SimpleClientHttpRequestFactory {
    @Override
    protected void prepareConnection(HttpURLConnection connection, String httpMethod) {
        try {
            if (!(connection instanceof HttpsURLConnection)) {
                //http協(xié)議
                super.prepareConnection(connection, httpMethod);
            }
            if ((connection instanceof HttpsURLConnection)) {
                HttpsURLConnection httpsURLConnection = (HttpsURLConnection) connection;
                //https協(xié)議
                KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
                //信任任何鏈接(也就是忽略認(rèn)證)
                TrustStrategy anyTrustStrategy = (chain, authType) -> true;
                SSLContext ctx = SSLContexts.custom().loadTrustMaterial(trustStore, anyTrustStrategy).build();
                httpsURLConnection.setSSLSocketFactory(ctx.getSocketFactory());
                super.prepareConnection(httpsURLConnection, httpMethod);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

效果
restTemplate轉(zhuǎn)發(fā)Https請求文章來源地址http://www.zghlxwxcb.cn/news/detail-472569.html

到了這里,關(guān)于restTemplate轉(zhuǎn)發(fā)Https請求的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • RestTemplate發(fā)起HTTPS請求Unsupported or unrecognized SSL message 報(bào)錯(cuò)解決

    原因:RestTemplate默認(rèn)是不支持HTTPS請求的,那么如果想使用RestTemplate發(fā)送一個(gè)HTTPS的請求 ,就需要對證書進(jìn)行處理,這里記錄一下一個(gè)可行的方法忽略證書的校驗(yàn)。 使用 RestTemplateBuilder 來構(gòu)建一個(gè) RestTemplate ,而非使用默認(rèn)。 requestFactory() 方法用來設(shè)置 ClientHttpRequestFactory 。

    2024年02月11日
    瀏覽(18)
  • nginx 如何將 https 請求轉(zhuǎn)發(fā)到 http

    nginx 如何將 https 請求轉(zhuǎn)發(fā)到 http

    網(wǎng)站之前是 https 的,通過 nginx 設(shè)置好了,現(xiàn)在不想用 https 了,但發(fā)散到外界的一些網(wǎng)址還是 https 的,此時(shí)只能通過 nginx 去轉(zhuǎn)發(fā) https 請求到 http 才能實(shí)現(xiàn)之前的鏈接能正常訪問。 具體設(shè)置如下: https 的其它設(shè)置不需要?jiǎng)樱恍枰?server 字段添加一條:

    2024年02月11日
    瀏覽(21)
  • Nginx接收Http協(xié)議請求轉(zhuǎn)發(fā)使用Https協(xié)議

    公司使用阿里的apigateway,規(guī)定不太友好,同是SIT環(huán)境,A系統(tǒng)的SIT1環(huán)境居然不能調(diào)用B系統(tǒng)的SIT2環(huán)境的接口。因?yàn)楦鱾€(gè)系統(tǒng)之間部署的SIT環(huán)境數(shù)量不同A系統(tǒng)可能只有1套,B系統(tǒng)可能有8套,這樣的話,可能會(huì)隨時(shí)切換調(diào)用B系統(tǒng)的環(huán)境,管理員不允許,于是想著用Nginx做下轉(zhuǎn)發(fā)。

    2024年02月08日
    瀏覽(28)
  • tengine/nginx https請求 轉(zhuǎn)發(fā) http upstream

    當(dāng)前的互聯(lián)網(wǎng)應(yīng)用基本都要支持https協(xié)議,而當(dāng)瀏覽器頭通過https協(xié)議將請求發(fā)到到負(fù)責(zé)負(fù)載的nginx后,會(huì)由當(dāng)前nginx再以http協(xié)議向后端upstream進(jìn)行請求,之所以這么做是因?yàn)閔ttps協(xié)議的安全性也帶來的額外的性能消耗。而源端基本都是在一個(gè)內(nèi)網(wǎng)里面的,對于通訊協(xié)議的安全性

    2024年01月23日
    瀏覽(31)
  • nginx負(fù)載轉(zhuǎn)發(fā)源請求http/https:X-Forwarded-Proto及nginx中的轉(zhuǎn)發(fā)報(bào)頭

    今天在排查服務(wù)器的問題時(shí)最后定位到服務(wù)器因?yàn)榻?jīng)過了運(yùn)維這一層的處理,轉(zhuǎn)發(fā)過來的請求不管用戶請求的是https還是http,我們的proxy服務(wù)器收到的都是80端口上的http。于是聯(lián)系相關(guān)部門了解有沒有現(xiàn)成的可用的這樣一個(gè)字段來獲得這個(gè)值。公司用的也是標(biāo)準(zhǔn)報(bào)頭,即X-Fo

    2024年02月16日
    瀏覽(18)
  • restTemplate發(fā)送https請求報(bào)錯(cuò)I/O error on POST request for “xxxx“: Remote host terminated the handshake解決

    restTemplate發(fā)送https請求報(bào)錯(cuò)I/O error on POST request for “xxxx“: Remote host terminated the handshake解決

    最近在項(xiàng)目開發(fā)中遇到了一個(gè)問題,用restTemplate調(diào)用https接口的時(shí)候一直掉不通,報(bào)錯(cuò)I/O error on POST request for “xxxx”: Remote host terminated the handshake;nested exception is javax.net.ssl.SSLHandshakeException: Remote host terminated the handshake 遠(yuǎn)程主機(jī)終止了握手 一開始以為是SSL證書的問題。在百度

    2024年02月11日
    瀏覽(30)
  • 使用Nginx的upstream實(shí)現(xiàn)負(fù)載均衡,并配置https,避免Post請求類型轉(zhuǎn)發(fā)后變?yōu)镚et

    使用Nginx的upstream實(shí)現(xiàn)負(fù)載均衡,并配置https,避免Post請求類型轉(zhuǎn)發(fā)后變?yōu)镚et

    Nginx支持負(fù)載均衡,可以很方便的幫助我們進(jìn)行水平擴(kuò)容,upstream就是nginx中的負(fù)載均衡模塊 當(dāng)客戶端發(fā)送請求時(shí),會(huì)先到Nginx,然后Nginx會(huì)將請求分發(fā)到后臺(tái)不同的服務(wù)器上。 如果后臺(tái)的服務(wù)器群中有一個(gè)宕機(jī)了,那么Nginx會(huì)自動(dòng)忽略這臺(tái)服務(wù)器,不會(huì)將請求再次分發(fā)到這臺(tái)

    2024年02月01日
    瀏覽(37)
  • 萬字長文講解調(diào)用第三方接口,RestTemplate,urlConnection使用詳解,java代碼模擬postman發(fā)送請求

    萬字長文講解調(diào)用第三方接口,RestTemplate,urlConnection使用詳解,java代碼模擬postman發(fā)送請求

    業(yè)務(wù)場景 :在日常開發(fā)中,經(jīng)常需要調(diào)用第三方接口,例如調(diào)用物流接口,此時(shí)需要利用urlConnection或者restTemplate模擬postman發(fā)送請求,請求支持加header ,設(shè)置content-type支持傳遞json;請求方式get,post,也可以需要傳遞文件,或者傳遞文件流; 下面這個(gè)例子就包含日常開發(fā)中大

    2024年02月05日
    瀏覽(22)
  • lua使用resty.http做nginx反向代理(https請求,docker容器化部署集群),一個(gè)域名多項(xiàng)目轉(zhuǎn)發(fā)

    lua使用resty.http做nginx反向代理(https請求,docker容器化部署集群),一個(gè)域名多項(xiàng)目轉(zhuǎn)發(fā)

    下載使用 鏈接:https://pan.baidu.com/s/1uQ7yCzQsPWsF6xavFTpbZg 提取碼:htay –來自百度網(wǎng)盤超級會(huì)員V5的分享 ad_load.lua文件

    2024年01月18日
    瀏覽(34)
  • RestTemplate通過HTTPS協(xié)議訪問接口

    RestTemplate 默認(rèn)不支持https協(xié)議,需要支持有兩種方式,第一種是忽略認(rèn)證,第二種是導(dǎo)入證書(比第一種安全) 在這里只實(shí)現(xiàn)第一種方式,實(shí)現(xiàn)代碼如下

    2024年02月11日
    瀏覽(19)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包