一、JAVA 使用RestTemplate发送post请求
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
@Service
@Slf4j
public class TestServiceImpl implements TestService {
@Autowired
private RestTemplate restTemplate;
private final String URL = "http://15.15.82.127:8124/api/test/getData";
private final String USER_NAME = "test";
private final String PASS_WORD = "test123";
第一种方法
//RestTemplate发送POST请求之带header,入参为json格式
@Override
p