将请求正文作为json发送以通过httpentity获取请求
将请求主体作为Json样本,通过外部API的GET请求发送 下面是需要在请求体中添加json以通过GET请求发送的示例 到外部API: '''将请求正文作为json发送以通过httpentity获取请求,json,spring-boot,resttemplate,http-get,httpentity,Json,Spring Boot,Resttemplate,Http Get,Httpentity,将请求主体作为Json样本,通过外部API的GET请求发送 下面是需要在请求体中添加json以通过GET请求发送的示例 到外部API: ''' {“名称识别”:[“名称-1”、“名称-2”、“名称-3”]} ''' '假设我从一个API获取值,如。。“Name-1”、“Name-2”、“Name-3”这些值是我需要的 通过GET请求传递给其他API。例如,下面我正在硬编码这些值以供参考…' ''' 字符串[]namesArray={“Name-1”、“Name-2”、“Name-3”} JSON
{“名称识别”:[“名称-1”、“名称-2”、“名称-3”]}
'''
'假设我从一个API获取值,如。。“Name-1”、“Name-2”、“Name-3”这些值是我需要的
通过GET请求传递给其他API。例如,下面我正在硬编码这些值以供参考…'
'''
字符串[]namesArray={“Name-1”、“Name-2”、“Name-3”}
JSONObject jsobObject=新的JSONObject();
put(“nameidentify”,namesArray);
HttpHeaders=新的HttpHeaders();
headers.add(“Accept”,MediaType.APPLICATION_JSON);
headers.add(“内容类型”,MediaType.APPLICATION_JSON);
HttpEntity otherentity=新的HttpEntity(jsobObject.toString(),headers);
ListgetnameResponse=restTemplate。
exchange(externalAPIurl,HttpMethod.GET
,其他实体,ArrayList.class)
.getBody();
当我调用外部API时,上面的代码导致400个错误请求。可能是他们没有收到的尸体。任何人都可以提供一些想法。提前感谢。。。
'''
{"nameidentify":["Name-1","Name-2","Name-3"]}
'''
'Assume i am getting values from one API like.. "Name-1","Name-2","Name-3" those values i need to
pass to other API through GET request.For example below i am hardcoding the values for reference...'
'''
String[] namesArray={"Name-1","Name-2","Name-3"}
JSONObject jsobObject=new JSONObject();
jsonObject.put("nameidentify",namesArray);
HttpHeaders headers=new HttpHeaders();
headers.add("Accept",MediaType.APPLICATION_JSON);
headers.add("Content-Type",MediaType.APPLICATION_JSON);
HttpEntity<String> otherentity=new HttpEntity<>(jsobObject.toString(),headers);
List<Map>getnameResponse=restTemplate.
exchange(externalAPIurl,HttpMethod.GET
,otherentity,ArrayList.class)
.getBody();