Android HttpPut - 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 HttpPut class.

This code example shows how to use the following methods:setEntity
		} 
		return null; 
	} 
 
    private void putUrl(String url, String data) throws Exception {
        HttpPut put = new HttpPut(url);
        put.setEntity(new StringEntity(data));
        HttpResponse response = executeRequest(put);
    } 
 
	protected HttpResponse executeRequest(HttpUriRequest request)
			throws ClientProtocolException, IOException { 
		DefaultHttpClient httpClient = new DefaultHttpClient();
		HttpResponse response = null;
		int retries = 3;
 
		while (retries-- > 0) {
			this.signRequest(request);
			response = httpClient.execute(request);
			int statusCode = response.getStatusLine().getStatusCode();
8
CodeRank
This code example shows how to use the following methods:
     * @param entity a raw {@link HttpEntity} to send with the request, for example, use this to send string/json/xml payloads to a server by passing a {@link org.apache.http.entity.StringEntity}. 
     * @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, HttpEntity entity, String contentType, AsyncHttpResponseHandler responseHandler) {
        sendRequest(httpClient, httpContext, addEntityToRequestBase(new HttpPut(url), entity), contentType, responseHandler, context);
    } 
     
    /** 
     * Perform a HTTP PUT request and track the Android Context which initiated the request. 
     * And set one-time headers for the request 
     * @param context the Android Context which initiated the request. 
     * @param url the URL to send the request to. 
     * @param headers set one-time headers for this request 
     * @param entity a raw {@link HttpEntity} to send with the request, for example, use this to send string/json/xml payloads to a server by passing a {@link org.apache.http.entity.StringEntity}. 
     * @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);
6
CodeRank
This code example shows how to use the following methods:setEntity, releaseConnection
            final FileBody fileBody = new FileBody( file );
 
            final MultipartEntity entity = new MultipartEntity();
            entity.addPart( file.getName(), fileBody );
             
            final HttpPut httpPut = new HttpPut();
            httpPut.setEntity( entity );
             
            Object response = httpJSONAPI( httpPut, getUpdateURI( appName ) );
             
            if( response instanceof JSONObject )
            { 
                JSONObject json = (JSONObject)response;
                 
                if( isSuccess( json ))
                { 
                    System.out.println( "updateApplication: success." ); //$NON-NLS-1$
                } 
                else 
                { 

7
CodeRank
This code example shows how to use the following methods:setEntity, abort, setHeader
		} 
	} 
 
	protected void putMethod(StreamData data, String url, String body) throws ArtAroundException {
		final AndroidHttpClient client = getNewHttpClient();
		final HttpPut putRequest = new HttpPut(url);
 
		try { 
			HttpEntity entity = new StringEntity(body);
			putRequest.setEntity(entity);
			putRequest.setHeader("Accept", "application/json");
			putRequest.setHeader("Content-Type", "application/json");
 
			HttpResponse response = client.execute(putRequest);
			parseHttpResponse(data, url, response);
		} 
		catch (IOException e) {
			throw new ArtAroundException(e);
		} 
		finally { 

8
CodeRank
This code example shows how to use the following methods:setEntity
 
	private StreamWriteObject swo = null;
	private StreamReadObject sro = null;
 
	public UriWriteObject(URI uri, Externalizable object) throws IOException {
		HttpPut httpPut = new HttpPut(uri.toASCIIString());
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		swo = new StreamWriteObject(baos);
		swo.write(object);
		swo.close(true);
		swo = null;
		sro = null;
		httpPut.setEntity(new ByteArrayEntity(baos.toByteArray()));
		execute(httpPut);
	} 
 
	public Externalizable getResponseObject() throws IOException,
			ClassNotFoundException { 
		sro = new StreamReadObject(httpResponse.getEntity().getContent());
		return sro.read();
6
CodeRank
This code example shows how to use the following methods:setEntity, addHeader, getParams
   * @throws ClientProtocolException 
   * @throws IOException 
   */ 
  public static ReadableResponse signedPutRequest(String request, String entity, CommonsHttpOAuthConsumer consumer, String contentType) throws OAuthMessageSignerException, OAuthExpectationFailedException, OAuthCommunicationException, ClientProtocolException, IOException{
    HttpClient client = new DefaultHttpClient();
    HttpPut put = new HttpPut(request);
    put.setEntity(new StringEntity(entity));
    put.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
    consumer.sign(put);
    put.addHeader("Content-Type", contentType);
    HttpResponse response = client.execute(put);
    return new HttpResponseWrapper(response);
  } 
 
  /** 
   * Sends a signed GET request using the Signpost library 
   * @param request the request's URL 
   * @param consumer the Signpost consumer object 
   * @param contentType the message's content type 
   * @return the response 
6
CodeRank
This code example shows how to use the following methods:setEntity, addHeader
	 
	public int putWithArgs(String targetURL, ArrayList<NameValuePair> pairs) {
		int statusCode = 0;
		 
		try { 
			HttpPut put = new HttpPut(baseURL() + targetURL);
			//Set headers manually because Android doesn't seem to care to 
			put.addHeader("X-Spree-Token", this.apiKey);
			if (pairs != null) {
				put.setEntity(new UrlEncodedFormEntity(pairs, "UTF-8"));
				//Log.d("RESTConnector.putWithArgs", "added pairs"); 
			} 
			HttpResponse response = client.execute(put);
			StatusLine statusLine = response.getStatusLine();
			statusCode = statusLine.getStatusCode();
			if (statusCode == 200 || statusCode == 201 || statusCode == 202) {
				HttpEntity entity = response.getEntity();
				String content = EntityUtils.toString(entity);
			} else { 
				Log.d("RESTConnector.genericRequest", "Response not 200, Status: " + statusCode);
6
CodeRank
This code example shows how to use the following methods:
	public <T extends Identifiable> void updateObject(T obj,
			NameValuePair... params) throws RedmineException {
		final EntityConfig<T> config = getConfig(obj.getClass());
		final URI uri = getURIConfigurator().getObjectURI(obj.getClass(),
				Integer.toString(obj.getId()));
		final HttpPut http = new HttpPut(uri);
 
		final String body = RedmineJSONBuilder.toSimpleJSON(
				config.singleObjectName, obj, config.writer);
		setEntity(http, body);
 
		getCommunicator().sendRequest(http);
	} 
 
	/** 
	 * Performs an "delete child Id" request. 
	 *  
	 * @param parentClass 
	 *            parent object id. 
	 * @param object 
5
CodeRank
This code example shows how to use the following methods:addHeader, setEntity, addHeader, getParams
 
		String fileName = sHelper.splitUriForFileName(imageUri);
		storageUri = Account.getStorageUrl() + "/" + containerName + "/" + fileName;
 
		HttpClient httpclient = new CustomHttpClient(context);
		HttpPut httpput = new HttpPut(storageUri);
		httpput.getParams().setIntParameter("http.socket.timeout", 100000);
 
		File file = new File(imageUri);
		ByteArrayEntity bae = null;
		try { 
			bae = new ByteArrayEntity(ByteHelper.getBytesFromFile(file));
		} catch (IOException e1) {
			e1.printStackTrace();
		} 
 
		httpput.setEntity(bae);
		httpput.addHeader("X-Auth-Token", Account.getAuthToken());
		httpput.addHeader("Content-Type", "application/octet-stream");
 

6
CodeRank
This code example shows how to use the following methods:setEntity, addHeader
    // PUT 
	public static void put (Context c, final String url, final JSONObject obj, final IRequestCallback callback, String user, String password) {
    	Log.i("HTTP PUT", url);
    	Log.i("JSON", obj.toString());
    	 
		HttpPut req = new HttpPut(url);
		req.addHeader("Accept", CONTENT_TYPE);
		req.addHeader("Content-Type", CONTENT_TYPE);
		 
	    StringEntity entity = null;
		try { 
			entity = new StringEntity(obj.toString(), ENCODING);
		} catch (UnsupportedEncodingException e) {
			ToastFacade.show(c, e);
		} 
	    entity.setContentType(CONTENT_TYPE);
	    req.setEntity(entity);
	    exec(c, req, callback, user, password);
    } 
	 

6
CodeRank

Related Android HttpPut Questions & Answers:

See Code Examples for Android HttpPut Methods: