所以,我在我的 Java 应用程序中有这个方法:
public String addAppointment(String service_id, String location_id, String start_date, String client_name, String client_phone, String client_email, String note, String session_token)
{
Map<String, String> args = new HashMap<String, String>();
args.put("service_id", service_id);
args.put("location_id", location_id);
args.put("start_date", start_date);
args.put("client_name", client_name);
args.put("client_phone", client_phone);
args.put("client_email", client_email);
args.put("note", note);
System.out.println(API_URL + "company/[censored]/appointment/?session_token="+ session_token);
String result = restTemplate.postForObject(API_URL + "company/[censored]/appointment/?session_token="+ session_token, args, String.class);
return result;
}
我收到了警告:
WARNING: POST request for "http://www.setster.com/api/v2/company/[censored]/appointment/?session_token=[censored]" resulted in 400 (Bad Request); invoking error handler
WARNING: StandardWrapperValve[setster]: PWC1406: Servlet.service() for servlet setster threw exception
当我更改该行时:
String result = restTemplate.postForObject(API_URL + "company/[censored]/appointment/?session_token="+ session_token, args, String.class);
为了:
String result = restTemplate.getForObject(API_URL + "company/[censored]/appointment/?session_token="+ session_token, String.class, args);
我从服务器收到一条带有正确响应的成功消息。但是,POST URL 很好,可以在 PHP 中使用 CURL 正常工作。
所以我的问题是。我做错了什么?还有其他选项可以使用postForObject创建帖子吗?