Using Simple Parameters Passed in x-www-form-urlencoded Format
For POST commands with x-www-form-urlencoded Content-Type, the body of the HTTP message sent to the server is one big query string, where name-value pairs are separated by ampersand (&), and names are separated from values by the equal symbol (=).
Make sure the web service method accepts POSTs with x-www-form-urlencoded Content-Type. You can verify this by checking the method definition in the Javadoc, which should look something like this:
POST Consumes({"application/x-www-form-urlencoded"})
URL: https://HOST:PORT/www/manager-service/rest/CaseService/getPersonalGroup
Normal response code: 200
For such cases, provide parameters in the form of simple URL-encoded name-value pairs, as in authToken and caseID below.
HashMap<String, String> params = new HashMap<String, String>();params.put("authToken", authToken);
params.put("caseID", caseId);
boolean first = true;StringBuffer sb = new StringBuffer();
for (Map.Entry<String, String> param : params.entrySet()) {
String keystr = URLEncoder.encode(param.getKey(), "UTF-8");
String paramstr = URLEncoder.encode(param.getValue(), "UTF-8");
if ( first ) { first = false;
} else {
sb.append("&");
}
sb.append(keystr).append("=").append(paramstr);
}
String paramStr = sb.toString();
In the above example, the string paramStr at the end of the code block constitutes the request body you want to send.
If all method parameters are simple Java objects or primitives, the correspondent web service method might also accept GET requests with all parameters added directly into URL. Use the standard format for preparing such URL:
<PROTOCOL>://<HOST>:<PORT>/www/<MODULE>/<SERVICE>/<METHOD>?parameters
where parameters are key-value pairs separated by ampersand (&) with URL-encoded values. For example:
https://<HOST>:8443/www/core-service/rest/LoginService/login?login=admin&password=password https://<HOST>:8443/www/manager-service/rest/CaseService/getCaseEventIDs?caseID=774c7vkQBABCAGdbEeuV1Aw%3D%3D&alt=json&authToken=
Tip: Do not use GET to send sensitive information like credentials. Instead, use a similar POST request where passed parameters are included in the request body and protected by the SSL protocol.