Android HttpEntityEnclosingRequestBase - 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 HttpEntityEnclosingRequestBase 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());
9
CodeRank
This code example shows how to use the following methods:setEntity, setHeader
This code example shows how to use the following methods:setEntity, setHeaders
     * @param contentType the content type of the payload you are sending, for example application/json if sending a json payload. 
     * @param responseHandler the response handler instance that should handle the response. 
     */ 
    public void put(Context context, String url,Header[] headers, HttpEntity entity, String contentType, AsyncHttpResponseHandler responseHandler) {
        HttpEntityEnclosingRequestBase request = addEntityToRequestBase(new HttpPut(url), entity);
        if(headers != null) request.setHeaders(headers);
        sendRequest(httpClient, httpContext, request, contentType, responseHandler, context);
    } 
 
    // 
    // HTTP DELETE Requests 
    // 
 
    /** 
     * Perform a HTTP DELETE request. 
     * @param url the URL to send the request to. 
     * @param responseHandler the response handler instance that should handle the response. 
     */ 
    public void delete(String url, AsyncHttpResponseHandler responseHandler) {
        delete(null, url, responseHandler);

7
CodeRank
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; 
    }; 
7
CodeRank
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));
		} 
		 
7
CodeRank
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
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);
 
7
CodeRank
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
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();
7
CodeRank
This code example shows how to use the following methods:setEntity, abort, setHeader
		} 
	} 
 
	protected void postMethod(StreamData data, String url, String body) throws ArtAroundException {
		final AndroidHttpClient client = getNewHttpClient();
		final HttpPost postRequest = new HttpPost(url);
		try { 
			HttpEntity entity = new StringEntity(body);
			postRequest.setEntity(entity);
			postRequest.setHeader("Accept", "application/json");
			postRequest.setHeader("Content-Type", "application/json");
 
			HttpResponse response = client.execute(postRequest);
			parseHttpResponse(data, url, response);
		} 
		catch (IOException e) {
			throw new ArtAroundException(e);
		} 
		finally { 
			if (postRequest != null) {

7
CodeRank

Related Android HttpEntityEnclosingRequestBase Questions & Answers:

See Code Examples for Android HttpEntityEnclosingRequestBase Methods: