I am trying to make this HTTP request via jsoup as given here:
http://api.decarta.com/v1/[KEY]/batch?requestType=geocode
And here is my code for that:
String postUrl = postURLPrefix + apiKey + "/batch?requestType=geocode";
String response = Jsoup.connect(postUrl).timeout(60000).ignoreContentType(true)
.header("Content-Type", "application/json;charset=UTF-8")
.method(Connection.Method.POST)
.data("payload", jsonPayload.toString())
.execute()
.body();
jsonPayload.toString() gives this:
{
"payload": [
"146 Adkins Street,Pretoria,Pretoria,Gauteng",
"484 Hilda Street,Pretoria,Pretoria,Gauteng",
"268 Von Willich Street,Centurion,Centurion,Gauteng",
...
]
}
Which is a perfectly valid JSON.
However, jsoup each time returns HTTP status code 400 (malformed).
So, how do I send proper HTTP POST with JSON payload using jsoup if this is possible at all? (Please note that it's payload and not an ordinary key-value pair in URL)