Sending Request body as json to GET request through httpentity

半城伤御伤魂 提交于 2021-01-29 07:09:04

问题


Sample Request Body as Json to send through the GET request for external API.

Below is sample json need to be added in Request Body to send through GET request to external API: '''

        {"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();
             
          

I am getting 400 Bad Request with the above code, when i am making call to external API. May be body they are not receiving. Can any one provide some ideas on this.Thanks in Advance... '''

来源:https://stackoverflow.com/questions/64683261/sending-request-body-as-json-to-get-request-through-httpentity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!