我正在尝试用java发送这个:
curl -H "Content-Type:application/json" -XPOST 'http://www.example.com/foo' -d '{"rootURL": "http://www.subway.com"}'
这是我的代码:
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://www.example.com/foo");
post.setHeader("Content-Type", "application/json");
List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
urlParameters.add(new BasicNameValuePair("rootURL", "http://www.subway.com"));
post.setEntity(new UrlEncodedFormEntity(urlParameters));
client.execute(post);
但我收到 400 错误:
Unexpected character ('r' (code 98)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at [Source: org.apache.catalina.connector.CoyoteInputStream@a18ba7b; line: 1, column: 2]
如果我改变这一行:
urlParameters.add(new BasicNameValuePair("rootURL", "http://www.subway.com"));
至
urlParameters.add(new BasicNameValuePair("bootURL", "http://www.subway.com"));
我收到以下错误:
Unexpected character ('b' (code 98)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at [Source: org.apache.catalina.connector.CoyoteInputStream@a18ba7b; line: 1, column: 2]
有谁知道问题是什么?