通过httpentity将请求正文作为json发送到GET请求

问题描述

将请求主体作为Json进行采样,以通过GET请求发送外部API。

下面是示例json,需要在请求正文中添加以通过GET请求发送 到外部API: '''

        {"nameidentify":["Name-1","Name-2","Name-3"]}
                
         '''
        
         'Assume i am getting values from one API like.. "Name-1","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-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();
             
          

当我调用外部API时,我收到上述代码的400错误请求。可能是他们没有收到的尸体。任何人都可以对此提供一些想法。在此先感谢... '''

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)