I am trying to get the jsoup equivalent of the following curl command
curl -X POST \
-d '{ "code": "7c7u......" }' \
-H 'Content-Type: application/json' \
-u 'userOfApi:passForUser' \
https://some.api.org.xyz/v2/oauth2/authorizations?
I am trying the following way
Connection con = Jsoup.connect(url)
.method(Connection.Method.POST)
.header("Content-Type", "application/json")
.header("Authorization", "Basic user:pass") // these are base64 encoded
.requestBody(data)
.userAgent("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.21 (KHTML, like Gecko) Chrome/19.0.1042.0 Safari/535.21")
.ignoreContentType(true);
But I can't seem to pass in the server user and password as specified by the curl -u
option. Any idea how I can achieve that as well with Jsoup ? or if not with Jsoup, then any other option.