Code example for HttpRequestBase

Methods: addHeader

0
   * @throws IOException 
   */ 
  public static ReadableResponse signedRequest(String verb, String request, CommonsHttpOAuthConsumer consumer, String contentType, List<NameValuePair> bodyParams) throws OAuthMessageSignerException, OAuthExpectationFailedException, OAuthCommunicationException, ClientProtocolException, IOException{
    HttpClient client = new DefaultHttpClient();
    HttpRequestBase reqObject = getRequestBaseByVerbParams(verb, request, bodyParams);
    consumer.sign(reqObject);
    reqObject.addHeader("Content-Type", contentType);
    HttpResponse response = client.execute(reqObject);
    return new HttpResponseWrapper(response);
  } 
 
  private static HttpRequestBase getRequestBaseByVerbEntity(String verb, String request, String entity) throws UnsupportedEncodingException {
    if(verb.equals(POST)){HttpPost post = new HttpPost(request); post.setEntity(new StringEntity(entity)); return post;}
    else if(verb.equals(GET)) return new HttpGet(request);
    else if(verb.equals(PUT)) {HttpPut put = new HttpPut(request); put.setEntity(new StringEntity(entity)); return put;}
    else if(verb.equals(DELETE)) return new HttpDelete(request);
    else Log.e("Utils", "Cannot reckognize the verb " + verb);
    return null; 
  } 
 
  private static HttpRequestBase getRequestBaseByVerbParams(String verb, String request, List<NameValuePair> bodyParams) throws UnsupportedEncodingException {