gpt4 book ai didi

java - Spring 休息模板

转载 作者:行者123 更新时间:2023-12-01 23:13:06 26 4
gpt4 key购买 nike

如何发送POST请求,消息正文中必须包含查询参数?

我尝试过:

MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
map.add("name", "xx");
map.add("password", "xx");

restTemplate.postForObject("URL", map, Response.class);

但是这不起作用。我想将数据发送到 bitstamp api。

编辑:我的 Spring Bean 似乎:

<bean id="restTemplate" class="org.springframework.web.client.RestTemplate">
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
</list>
</property>
</bean>

编辑2:我的代码似乎

List<MediaType> acceptableMediaTypes = new ArrayList<MediaType>();
acceptableMediaTypes.add(MediaType.APPLICATION_JSON);// or any other

HttpHeaders headers = new HttpHeaders();
headers.setAccept(acceptableMediaTypes);

HttpEntity<String> requestEntity = new HttpEntity<String>("key=XX&nonce=XX&signature=XX", headers);
ResponseEntity<AccountBalance> responseEntity = restTemplate.exchange(
"https://www.bitstamp.net/api/balance/", HttpMethod.POST, requestEntity, AccountBalance.class);

现在的响应:缺少 key 、签名和随机数参数

但应该是:未找到API key

最佳答案

你必须使用restTemplate.exchange

示例:

List<MediaType> acceptableMediaTypes = new ArrayList<MediaType>();
acceptableMediaTypes.add(MediaType.APPLICATION_JSON);// or any other

HttpHeaders headers = new HttpHeaders();
headers.setAccept(acceptableMediaTypes);

HttpEntity<String> requestEntity = new HttpEntity<String>("name=XX&password=XX",headers);
ResponseEntity<Response> responseEntity = restTemplate.exchange("URL", HttpMethod.POST, requestEntity, Response.class);

关于java - Spring 休息模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21559325/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com