I have something like the following:
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();
It keeps coming back with a 500. The service provider says I need to send JSON. How is that done with Apache HttpClient 3.1+?
NameValuePair
just adds a request parameter, you're not sending any JSON in your code. What JSON structure does the service expect to receive, what's your data to send? You're looking forpostMethod.setRequestEntity()
with aStringRequestEntity
that contains your JSON. – Thisbe