无法使用Spring RestTemplate客户端将请求参数发送到HttpServeletRequest doPost

问题描述

我正在使用Spring RestTemplate客户端对另一个应用程序进行POST调用,该应用程序将此请求作为HTTpServletRequest处理。 问题是HTTpServletRequest需要一个键值对,例如

$urlsta = "https://hubeau.eaufrance.fr/api/v1/hydrometrie/referentiel/stations?code_departement=71&en_service=true&format=json&size=50";
$raw = file_get_contents($urlsta);
$json = json_decode($raw,true);
usort($json['data'],function($a,$b) { return $a->libelle_commune > $b->libelle_commune ? -1 : 1; });                                                            
foreach($json['data'] as $ligne) {
  echo "<option value='".$ligne['code_station']."' ";
  echo ">".$ligne['libelle_commune']." - ".$ligne['libelle_cours_eau']."</option>";
}

这是两端的代码段-

我的应用-

String xmlString = request.getParameter("xml12")
//xmlString should be  "`<parent><child></child></parent>`" but coming as null.

其他应用-

String data = "`<parent><child></child></parent>`"

HttpHeaders header = new HttpHeaders()

header.setContentType(MediaType.APPLICATION_XML)

Map<String,String> bodyParamMap = new HashMap<String,String>();
bodyParamMap.put("xml123",data)

String reqBodyData = new ObjectMapper().writeValuesAsstring(bodyParamMap)

httpentity<String> entity = new httpentity<String>(reqBodyData,header)

RestTemplate rt = new RestTemplate()

String response = rt.postForObject("url",entity,String.class)
//Getting response as 500

我只想知道我的错误以及如何将我的数据字符串传递到发布请求,以便HttpServletRequest request = new HttpServletRequest() String xmlString = request.getParameter("xml123") // xmlString is null 以String的形式接收我的数据xml。

解决方法

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

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

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