我正在使用spring 4.我正在尝试调用restTemplate.postForEntity但是继续使用
<bean id="restTemplate" name="restTemplate"
class="org.springframework.web.client.RestTemplate"
autowire-candidate="true">
<constructor-arg ref="httpClientFactory" />
<property name="messageConverters">
<list>
<bean
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
</bean>
<bean class="org.springframework.http.converter.FormHttpMessageConverter" />
<bean
class="org.springframework.http.converter.StringHttpMessageConverter" />
</list>
</property>
</bean>
我的休息模板配置:
protected <T> T doExecute(String suffixUrl, MultiValueMap<String, String> requestBody, Class<T> responseType) {
String prefixUrl = "https://blabla.com/api/bla/";
ResponseEntity<T> responseEntity = null;
HttpHeaders headers = new HttpHeaders();
headers.add(
"Content-type",
"application/x-www-form-urlencoded");
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(
requestBody, headers);
responseEntity = restTemplate.postForEntity(
prefixUrl + suffixUrl,
request,
responseType);
return responseEntity.getBody();
}
我的函数调用:
String templateList = this.doExecute(
"list.json",
map,
String .class);
ObjectMapper mapper = new ObjectMapper();
TemplateResponse[] tr = mapper.readValue(
templateList,
TemplateResponse[].class);
我感觉它与响应“Content-Encoding:gzip”有关,我一直在寻找一个gzip转换器,但它只存在于spring android中。
编辑: 这可行,但它只是一个解决方法:
echo shell_exec("cd /mypath; /usr/local/bin/php -q push_script.php -q '{$usertoken}'");