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
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: setEntity, setHeader
		 
		String url = options.getHost() + Defaults.ENDPOINTS.get("import");
		String json = batch.toString();
		 
		HttpClient httpclient = new DefaultHttpClient(); 
		HttpPost post = new HttpPost(url);
		post.setHeader("Content-Type", "application/json");
 
		try { 
		      ByteArrayEntity se = new ByteArrayEntity(json.getBytes());  
		      se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
		      post.setEntity(se);
		       
		      return httpclient.execute(post);
		} 
		catch(Exception e){
			Logger.w("Failed to send request. " +  
		    		Log.getStackTraceString(e));
		} 
		 
Full Snippet Info
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: setEntity, setHeader
            if (method.equals("GET")) {
                url = url + "?" + encodeUrl(params);
                HttpGet get = new HttpGet(url);
                request = get;
            } else if (method.equals("POST")) {
                HttpPost post = new HttpPost(url);
                byte[] data = null;
                bos = new ByteArrayOutputStream(1024 * 50);
                if (!TextUtils.isEmpty(file)) {
                    Utility.paramToUpload(bos, params);
                    post.setHeader("Content-Type", MULTIPART_FORM_DATA + "; boundary=" + BOUNDARY);
                    Bitmap bf = BitmapFactory.decodeFile(file);
 
                    Utility.imageContentToUpload(bos, bf);
 
                } else { 
                    post.setHeader("Content-Type", "application/x-www-form-urlencoded");
                    String postParam = encodeParameters(params);
                    data = postParam.getBytes("UTF-8");
                    bos.write(data);

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: setEntity
		formparams.add(new BasicNameValuePair("age", "28"));
		formparams.add(new BasicNameValuePair("flag", "false"));
		formparams.add(new BasicNameValuePair("dateOfBirth", ""));
		UrlEncodedFormEntity postEntity = new UrlEncodedFormEntity(formparams, "UTF-8");
 
		post.setEntity(postEntity);
 
		CloseableHttpResponse response = client.execute(post);
		try { 
			HttpEntity entity = response.getEntity();
			assertThat(entity).isNotNull();
			String responseString = EntityUtils.toString(entity);
 
			Map<String, Object> rootAsMap = mapper.readValue(responseString, Map.class);
			assertThat(rootAsMap).hasSize(5);
			assertThat(rootAsMap.get("method")).isEqualTo("updateUser");
			assertThat(rootAsMap.get("type")).isEqualTo("rpc");
			assertThat(rootAsMap.get("action")).isEqualTo("userServiceInitBinderService");
			assertThat(rootAsMap.get("tid")).isEqualTo(1);
 
Full Snippet Info
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: setEntity
	@Test 
	public void testPost() throws IOException { 
		CloseableHttpClient client = HttpClientBuilder.create().build();
		CloseableHttpResponse response = null;
		try { 
			HttpPost post = new HttpPost("http://localhost:9998/controller/router");
 
			List<NameValuePair> formparams = new ArrayList<NameValuePair>();
			formparams.add(new BasicNameValuePair("extTID", "1"));
			formparams.add(new BasicNameValuePair("extAction", "infoController"));
			formparams.add(new BasicNameValuePair("extMethod", "updateInfo"));
			formparams.add(new BasicNameValuePair("extType", "rpc"));
			formparams.add(new BasicNameValuePair("extUpload", "false"));
			formparams.add(new BasicNameValuePair("userName", "RALPH"));
			UrlEncodedFormEntity postEntity = new UrlEncodedFormEntity(formparams, "UTF-8");
 
			post.setEntity(postEntity);
 
			response = client.execute(post);
			HttpEntity entity = response.getEntity();

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: setEntity, setParams
		@Override 
		protected JSONObject doInBackground(String... params) {
  
			JSONObject jso = null;
			try { 
				HttpPost post = new HttpPost("http://twitter.com/statuses/update.json");
				LinkedList<BasicNameValuePair> out = new LinkedList<BasicNameValuePair>();
				out.add(new BasicNameValuePair("status", params[0]));
				post.setEntity(new UrlEncodedFormEntity(out, HTTP.UTF_8));
				post.setParams(getParams());
				// sign the request to authenticate 
				mConsumer.sign(post);
				String response = mClient.execute(post, new BasicResponseHandler());
				jso = new JSONObject(response);
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			} catch (OAuthMessageSignerException e) {
				e.printStackTrace();
			} catch (OAuthExpectationFailedException e) {
				e.printStackTrace();
Full Snippet Info
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

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: