Android HttpPost - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android HttpPost class.

This code example shows how to use the following methods: setEntity, addHeader, setParams
    try { 
      Log.w("MmsSender", "Sending MMS1 of length: " + (mms != null ? mms.length : "null"));
      client                 = constructHttpClient(context, parameters);
      URI targetUrl          = new URI(parameters.getMmsc());
      HttpHost target        = new HttpHost(targetUrl.getHost(), targetUrl.getPort(), HttpHost.DEFAULT_SCHEME_NAME);
      HttpPost request       = new HttpPost(parameters.getMmsc());
      ByteArrayEntity entity = new ByteArrayEntity(mms);
 
      entity.setContentType("application/vnd.wap.mms-message");
 
      request.setEntity(entity);
      request.setParams(client.getParams());
      request.addHeader("Accept", "*/*, application/vnd.wap.mms-message, application/vnd.wap.sic");
//      request.addHeader("x-wap-profile", "http://www.htcmms.com.tw/Android/Common/nexusone/ua-profile.xml"); 
      request.addHeader("x-wap-profile", "http://www.google.com/oha/rdf/ua-profile-kila.xml");
      HttpResponse response = client.execute(target, request);
      StatusLine status     = response.getStatusLine();
 
      if (status.getStatusCode() != 200)
        throw new IOException("Non-successful HTTP response: " + status.getReasonPhrase());
Full Snippet Info
9
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods:
        HttpResponse response = httpclient.execute(new HttpGet(cookieReadURL.toURI() + "CookieReadServlet"));
        if (response.getEntity() != null)
            response.getEntity().getContent().close();
 
        log.info("Sending request with cookie"); 
        response = httpclient.execute(new HttpPost(cookieReadURL.toURI() + "CookieReadServlet"));
    } 
 
    @Test 
    public void testCookieRetrievedCorrectly() throws Exception { 
        log.info("testCookieRetrievedCorrectly()"); 
        DefaultHttpClient httpclient = new DefaultHttpClient();
        HttpResponse response = httpclient.execute(new HttpGet(cookieURL.toURI() + "CookieServlet"));
 
        // assert that we are able to hit servlet successfully 
        int postStatusCode = response.getStatusLine().getStatusCode();
        Header[] postErrorHeaders = response.getHeaders("X-Exception");
        assertTrue("Wrong response code: " + postStatusCode, postStatusCode == HttpURLConnection.HTTP_OK);
        assertTrue("X-Exception(" + Arrays.toString(postErrorHeaders) + ") is null", postErrorHeaders.length == 0);
 
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: setEntity, setHeader
This code example shows how to use the following methods: setHeaders
     * @param responseHandler the response handler instance that should handle 
     *        the response. 
     */ 
    public void post(Context context, String url, Header[] headers, RequestParams params, String contentType,
            AsyncHttpResponseHandler responseHandler) {
        HttpEntityEnclosingRequestBase request = new HttpPost(url);
        if(params != null) request.setEntity(paramsToEntity(params));
        if(headers != null) request.setHeaders(headers);
        sendRequest(httpClient, httpContext, request, contentType,
                responseHandler, context);
    } 
 
    /** 
     * Perform a HTTP POST request and track the Android Context which initiated 
     * the request. Set headers only for this request 
     * 
     * @param context the Android Context which initiated the request. 
     * @param url the URL to send the request to. 
     * @param headers set headers only for this request 
     * @param entity a raw {@link HttpEntity} to send with the request, for 
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: setEntity, addHeader
        HttpClient httpclient = new DefaultHttpClient();
        String headerValue = DropboxUtils.getFileExchangeAuthHeader(authToken, authTokenSecret);
         
        // See related encoding change in DropboxDownloadHelper. 
        String url = FILE_UPLOAD_URL + URLEncoder.encode(fileName, "UTF-8").replace("+", "%20");
        HttpPost httppost = new HttpPost(url);
        httppost.addHeader("Authorization", headerValue);
        httppost.setEntity(new FileEntity(new File(filePath), "application/x-sqlite3"));
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity resEntity = response.getEntity();
        if(response.getStatusLine().getStatusCode() == 200 && resEntity != null){
            InputStream is = resEntity.getContent();
            JSONObject jsonResponse = new JSONObject(IOUtils.toString(is));
            if(jsonResponse.getString("modified") != null){
                is.close();
                return true; 
            } 
        } 
        return false; 
    }; 
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE

Related Android HttpPost Questions & Answers:

Other Android HttpPost Examples

4:				// defaultHttpClient
5:				DefaultHttpClient httpClient = new DefaultHttpClient();
6:				HttpPost httpPost = new HttpPost(url);
7:	
8:				HttpResponse httpResponse = httpClient.execute(httpPost);
-
4:				// defaultHttpClient
5:				DefaultHttpClient httpClient = new DefaultHttpClient();
6:				HttpPost httpPost = new HttpPost(url);
7:	
8:				HttpResponse httpResponse = httpClient.execute(httpPost);

Read More

27:			HttpClient httpClient = new DefaultHttpClient();
28:			// Creating HTTP Post
29:			HttpPost httpPost = new HttpPost(
30:					"http://www.example.com/login");
31:	
-
27:			HttpClient httpClient = new DefaultHttpClient();
28:			// Creating HTTP Post
29:			HttpPost httpPost = new HttpPost(
30:					"http://www.example.com/login");
31:

Read More

50:				// Checking http request method type
51:				if (method == POST) {
52:					HttpPost httpPost = new HttpPost(url);
53:					// adding post params
54:					if (params != null) {
-
50:				// Checking http request method type
51:				if (method == POST) {
52:					HttpPost httpPost = new HttpPost(url);
53:					// adding post params
54:					if (params != null) {

Read More

See Code Examples for Android HttpPost Methods: