Reputation: 3527
I'm attempting to do an HttpURLConnection POST request to a webservice API.
The body of the request requires 2+ levels of parameters, for instance:
<fields>
<field>title</field>
<field>description</field>
</fields>
Right now I have this, which gives me a 500 error:
URL url = new URL(strUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setRequestProperty("Content-Type", "application/xml");
conn.setRequestProperty("field", "title");
conn.setRequestProperty("field", "author");
conn.connect();
I've connected to this via Firefox's RESTClient but can't do it through code.
How do I assing each field
value with .setRequestProperty
? I'm also open to better ways of doing this request.
Upvotes: 0
Views: 127
Reputation: 2712
What you're doing won't work, HttpURLConnection.setRequestProperty is used to set HTTP headers.
You need to create the XML document and POST it to the server.
Upvotes: 1