Hi,
I would like to reate a POST request to a given address, let it for example be
http://staging.myproject.com/products.xml?product[title]=TitleTest&product[content]=TestContent&product[price]=12.3&tags=aaa,bbb
for POST requests I've created an universal method:
private String postMethod(String url, HashMap<String, String> headers, String encodedAuthorizationString) throws HttpException, IOException {
HttpClient client = new HttpClient();
PostMethod post = new PostMethod(url);
post.setRequestHeader("Authorization", encodedAuthorizationString);
if(headers != null && !headers.isEmpty()){
for(Entry<String, String> entry : headers.entrySet()){
post.setRequestHeader(new Header(entry.getKey(), entry.getValue()));
}
}
client.executeMethod(post);
String responseFromPost = post.getResponseBodyAsString();
post.releaseConnection();
return responseFromPost;
}
where headers represents pairs (key, value), for example ("product[title]", "TitleTest"). I tried to use the method by calling postMethod("http://staging.myproject.com.products.xml", headers, "xxx"); where headers included pairs
("product[title]", "TitleTest"),
("product[content]", "TestContent"),
(product[price], "12.3"),
("tags", "aaa,bbb")
but the server returned an error message.
Does anyone know how to parse the address
http://staging.myproject.com/products.xml?product[title]=TitleTest&product[content]=TestContent&product[price]=12.3&tags=aaa,bbb
in order to use it with the method above? Which part is url? Are parameters set correctly?
Thank you.