1、首先我们搭建好maven工程,加好对应的依赖
2、测试一个get请求带参数的方式
@Test
public void test3(){
CloseableHttpClient hc = HttpClients.createDefault();
CloseableHttpResponse response;
String url = "";//填写自己的url地址 例如https://www.sogou.com/web
try {
URIBuilder builder = new URIBuilder(url);
builder.addParameter("zhuanlisqh", "2021126590594");//传的参数,,对应的key和value
HttpGet httpGet = new HttpGet(builder.build());
httpGet.setHeader("User-Agent","Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36");
response = hc.execute(httpGet);
HttpEntity entity = response.getEntity();
String result = EntityUtils.toString(entity, StandardCharsets.UTF_8);
System.out.println("结果是:" + result);
} catch (Exception e) {
e.printStackTrace();
}
}
3、可以使用FeignClient的方式进行调用
import com.alibaba.fastjson.JSONObject;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
/**
* @author
* @version 1.0
* @title: GuoJIasqOnlionFeign
* @projectName ecloud-app-flsx
* @description:
* @date 2021/12/3 20:41
*/
@FeignClient(url="http://10.1111.111.2115:8060",name="GuoJIasqOnlionFeign")
public interface GuoJIasqOnlionFeign {
@RequestMapping(value ="/zxsq-guojia/tijiaor-info",method = RequestMethod.GET)
JSONObject getTijiaorInfo(@RequestParam String zhuanlisqh);
}
4、然后在业务逻辑里面注入GuoJIasqOnlionFeign ,然后调用即可