Code example for DefaultHttpClient

Methods: executegetCredentialsProvidergetParams

0
    } 
     
    public String sendPost(URI uri, String path, Map<String, String> params, String contentType) {
		Credentials creds = new UsernamePasswordCredentials(params.get("username"), params.get("password"));
		AuthScope authscope = new AuthScope(uri.getHost(), uri.getPort());
		httpClient.getCredentialsProvider().setCredentials(authscope, creds);
		JSONObject data = new JSONObject(params);
    	 
        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);
 
            if (response != null) {
                this.json = readJSONObject(response);
                ret = EntityUtils.toString(response.getEntity());
            } 
Stop searching for code, let great code find you!  Add Codota to your java IDE