Code example for HttpPost

Methods: setEntity, setHeader

0
    	 
        String ret = null;
 
        httpClient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.RFC_2109);
 
        httpPost = new HttpPost(uri);
        response = null;
 
        StringEntity tmp = null;        
 
        Log.d("Your App Name Here", "Setting httpPost headers");
 
        httpPost.setHeader("User-Agent", "SET YOUR USER AGENT STRING HERE");
        httpPost.setHeader("Accept", "text/html,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");
 
        if (contentType != null) {
            httpPost.setHeader("Content-Type", contentType);
        } else { 
            httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
        } 
 
        try { 
            tmp = new StringEntity(data.toString(), "UTF-8");
        } catch (UnsupportedEncodingException e) {
            Log.e("Your App Name Here", "HttpUtils : UnsupportedEncodingException : "+e);
        } 
 
        httpPost.setEntity(tmp);
 
        Log.d("Your App Name Here", uri + "?" + data);
 
        try { 
            response = httpClient.execute(httpPost,localContext);