gpt4 book ai didi

java - 使用 Rest 模板对外部网站进行 PUT 调用

转载 作者:太空宇宙 更新时间:2023-11-04 10:14:51 27 4
gpt4 key购买 nike

我目前正在尝试对我的 Gemfire Cache 测试环境进行 PUT 调用 https://gemfire.docs.pivotal.io/95/geode/rest_apps/put_update_data.html

我尝试过遵循这样的模板

 RestTemplate restTemplate = new RestTemplate();
String url = "http://localhost:8080/spring-rest/data/putdata/{id}/{name}";
Map<String, String> map = new HashMap<String, String>();
map.put("id", "100");
map.put("name", "Ram");
Address address = new Address("Dhananjaypur", "Varanasi","UP");
restTemplate.put(url, address, map);
}

在我的情况下,它会看起来像这样吗?

 RestTemplate restTemplate = new RestTemplate();
String url = "gemfire.com/gemfire-api/v1/{region}/{key};
Map<String, String> map = new HashMap<String, String>();
map.put("region", "1");
map.put("key", "testKey");
restTemplate.put(url, "testStringtoPut", map);
}

此模板会导致我出现 404 未找到错误,有人可以提供有关执行此操作的正确方法的见解吗?

最佳答案

尝试这样做,它应该有效

HttpEntity<String> request = new HttpEntity<String>(address.toString());

String url=http://localhost:8080/spring-rest/data/putdata/100/"Ram"

ResponseEntity <String> response= template.exchange(url,HttpMethod.PUT,request,String.class);

关于java - 使用 Rest 模板对外部网站进行 PUT 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51848321/

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