RestTemplateコールサービス
4026 ワード
テスト-------------------------
package com.example.demo.controller;
import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.*;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
* desc:
* author CDN
* create 2019-11-06 17:21
* version 1.0.0
*/
@RestController
@Configuration
public class Ter {
@Autowired
private RestTemplate restTemplate;
@Bean
public RestTemplate restTemplate(ClientHttpRequestFactory factory) {
RestTemplate restTemplate = new RestTemplate(factory);
restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
return restTemplate;
}
@Bean
public ClientHttpRequestFactory simpleClientHttpRequestFactory() {
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
factory.setReadTimeout(5000);// ms
factory.setConnectTimeout(5000);// ms
return factory;
}
/**
* desc:
* param: []
* return:
* author: CDN
* date: 2019/11/6
*/
@RequestMapping("qq")
public Object aa(){
return startHttpMethod("http://127.0.0.1:8087/api/admin/v1/bid/list?pageIndex=0&pageSize=10",null,"post");
}
public String startHttpMethod(String ReqAdderss, List