* @throws IOException
* @throws ClientProtocolException
*/
public static HttpResponse executePost(String targetURL, POLICY authPolicy, HttpParams params, Model model) throws SocialHttpClientException {
HttpHost targetHost = new HttpHost(SocialClientContext.getHost(), SocialClientContext.getPort(), SocialClientContext.getProtocol());
SocialHttpClient httpClient = SocialHttpClientImpl.newInstance();
if (POLICY.BASIC_AUTH == authPolicy) {
try {
httpClient.setBasicAuthenticateToRequest();
} catch (SocialClientLibException e) {
throw new SocialHttpClientException(e.getMessage(), e);
}
}
HttpPost httpPost = new HttpPost(targetURL);
Header header = new BasicHeader("Content-Type", "application/json");
httpPost.setHeader(header);
//Post method with the HttpParams
if (params != null) {
httpPost.setParams(params);
}
try {
//Provides when uses post so does not have any data.
byte[] postData = convertModelToByteArray(model);
if (postData != null) {
ByteArrayEntity entity = new ByteArrayEntity(convertModelToByteArray(model));
httpPost.setEntity(entity);
}
HttpResponse response = httpClient.execute(targetHost, httpPost);
//handleError(response);
//Debugging in the devlopment mode
if (SocialClientContext.isDeveloping()) {
dumpHttpResponsetHeader(response);