springBoot自帶的傳送HTTP請求的API

2021-08-30 08:46:18 字數 1110 閱讀 5560

springboot管理的專案,自動傳送http請乙個自動網頁獲取鏈結,首先考慮到用httpclient api,經同事指點用了springboot自帶的api,**非常簡潔,兩行**如下。

resttemplate resttemplate = new resttemplate;

string forobject = resttemplate.getforobject(url,string.class);

環境spring boot

pom.xml (核心內容)

org.springframework.boot

spring-boot-starter-parent

1.4.2.release

org.springframework.boot

spring-boot-starter-web

--------------------- 

resttemplate.getforobject(url, string.class); // 向url傳送 get型別請求,將返回結果 以string型別顯示 // 能很明顯發現無法設定編碼格式等,亂碼等問題無法解決

預設的 resttemplate 有個機制是請求狀態碼非200 就丟擲異常,會中斷接下來的操作,如果要排除這個問題那麼需要覆蓋預設的 responseerrorhandler ,下面為用什麼也不幹覆蓋預設處理機制

body.add("var1","測試資料1");

spring boot 傳送郵件

簡單幾步,實現在spring boot中傳送郵件 1 引入依賴 org.springframework.boot spring boot starter mail spring mail host smtp.exmail.qq.com username 使用者名稱 password 密碼 prope...

springboot傳送郵件

pom導包 繼承springboot 新增springbootmail依賴 springboot測試和springboot配置依賴 org.springframework.boot spring boot starter parent 2.0.7.release org.springframewor...

SpringBoot自帶的定時器

1 新增依賴 org.springframework.boot spring boot starter 2 啟動類上新增註解 enablescheduling 3 建立定時執行的任務類 兩種方式 方式一 component public class schedulertask 方式二 compone...