如何使用Apache HttpClient发布JSON请求?
2022-08-31 10:00:05
我有类似下面的内容:
final String url = "http://example.com";
final HttpClient httpClient = new HttpClient();
final PostMethod postMethod = new PostMethod(url);
postMethod.addRequestHeader("Content-Type", "application/json");
postMethod.addParameters(new NameValuePair[]{
new NameValuePair("name", "value)
});
httpClient.executeMethod(httpMethod);
postMethod.getResponseBodyAsStream();
postMethod.releaseConnection();
它不断以500回来。服务提供商说我需要发送JSON。Apache HttpClient 3.1+是如何做到这一点的?