in src/main/java/com/vmware/vim/rest/RestClient.java [153:199]
public String post(String urlStr, Map<String, String> para) throws Exception
{
urlStr = preProcessUrl(urlStr);
HttpURLConnection getCon = (HttpURLConnection) new URL(
urlStr).openConnection();
getCon.connect();
String cookie = getCon.getHeaderField("Set-Cookie");
cookie = cookie.substring(0, cookie.indexOf(";"));
//As of 4.1u1, a hidden input is added into form, shown as follows
//<input name="vmware-session-nonce" type="hidden" value="52f3d5cc-5664-6d09-cd3a-73869a2de488">
String nonceStr = findVMwareSessionNonce(getCon.getInputStream());
HttpURLConnection postCon = (HttpURLConnection) new URL(urlStr).openConnection();
postCon.setRequestMethod("POST");
postCon.setDoOutput(true);
postCon.setDoInput(true);
postCon.setRequestProperty("Cookie", cookie);
OutputStream os = postCon.getOutputStream();
OutputStreamWriter out = new OutputStreamWriter(os);
if(nonceStr!=null)
{
out.write(NONCE + "=" + nonceStr);
}
Iterator<String> keys = para.keySet().iterator();
while(keys.hasNext())
{
String key = keys.next();
String value = para.get(key);
key = URLEncoder.encode(key, "UTF-8");
value = URLEncoder.encode(value, "UTF-8");
out.write(key + "=" + value);
}
out.close();
InputStream is = postCon.getInputStream();
StringBuffer sb = readStream(is);
String resultFlag = "Method Invocation Result:";
int start = sb.indexOf(resultFlag);
String result = sb.substring(start + resultFlag.length());
return ResultConverter.convert2Xml(result);
}