Search in sources :

Example 1 with ClientProtocolException

use of org.apache.http.client.ClientProtocolException in project coinbase-bitmonet-sdk by coinbase.

the class HTTPUtils method makeHttpPostRequest.

public static HttpResponse makeHttpPostRequest(String path) {
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(path);
    try {
        return httpclient.execute(httppost);
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) IOException(java.io.IOException) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) ClientProtocolException(org.apache.http.client.ClientProtocolException)

Example 2 with ClientProtocolException

use of org.apache.http.client.ClientProtocolException in project Trello-Android by chrisHoekstra.

the class TrelloService method getNotifications.

public ArrayList<NotificationVO> getNotifications() {
    ArrayList<NotificationVO> result = null;
    ArrayList<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
    params.add(new BasicNameValuePair("key", PUBLIC_KEY));
    params.add(new BasicNameValuePair("token", mToken));
    HttpGet httpGet = new HttpGet(TRELLO_API_URL + "members/" + "me/" + "notifications?" + URLEncodedUtils.format(params, "UTF-8"));
    HttpClient httpClient = getHttpClient();
    try {
        httpGet.setHeader("Accept", "application/json, text/javascript, */*; q=0.01");
        httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, USER_AGENT_STRING);
        HttpResponse response = httpClient.execute(httpGet, mContext);
        if (response != null) {
            result = mObjectMapper.readValue(mJsonFactory.createJsonParser(new InputStreamReader(response.getEntity().getContent(), "UTF-8")), new TypeReference<ArrayList<NotificationVO>>() {
            });
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return result;
}
Also used : InputStreamReader(java.io.InputStreamReader) NotificationVO(com.chrishoekstra.trello.vo.NotificationVO) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) HttpGet(org.apache.http.client.methods.HttpGet) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) TypeReference(org.codehaus.jackson.type.TypeReference) IOException(java.io.IOException) ClientProtocolException(org.apache.http.client.ClientProtocolException)

Example 3 with ClientProtocolException

use of org.apache.http.client.ClientProtocolException in project Trello-Android by chrisHoekstra.

the class TrelloService method addCard.

public Boolean addCard(String boardListId, String name) {
    Boolean result = false;
    ArrayList<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
    params.add(new BasicNameValuePair("key", PUBLIC_KEY));
    params.add(new BasicNameValuePair("token", mToken));
    params.add(new BasicNameValuePair("name", name));
    params.add(new BasicNameValuePair("idList", boardListId));
    HttpPost httpPost = new HttpPost(TRELLO_API_URL + "cards?" + URLEncodedUtils.format(params, "UTF-8"));
    HttpClient httpClient = getHttpClient();
    try {
        httpPost.setHeader("Accept", "application/json, text/javascript, */*; q=0.01");
        httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, USER_AGENT_STRING);
        HttpResponse response = httpClient.execute(httpPost, mContext);
        if (response != null) {
            result = true;
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return result;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) ClientProtocolException(org.apache.http.client.ClientProtocolException)

Example 4 with ClientProtocolException

use of org.apache.http.client.ClientProtocolException in project UltimateAndroid by cymcsg.

the class HttpUtils_Deprecated method loadImageFromUrl.

public static byte[] loadImageFromUrl(String url) {
    InputStream i = null;
    byte[] filename = null;
    try {
        byte[] dbfilename = null;
        DefaultHttpClient httpClient = new DefaultHttpClient();
        String geturl = url;
        HttpGet request = new HttpGet(geturl);
        request.setHeader("referer", "http://pic.qingdaonews.com");
        HttpResponse response = httpClient.execute(request);
        i = response.getEntity().getContent();
        ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
        int ch;
        while ((ch = i.read()) != -1) {
            bytestream.write(ch);
        }
        filename = bytestream.toByteArray();
        bytestream.close();
        i.close();
        return filename;
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return filename;
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) ClientProtocolException(org.apache.http.client.ClientProtocolException)

Example 5 with ClientProtocolException

use of org.apache.http.client.ClientProtocolException in project Anki-Android by Ramblurr.

the class HttpUtility method postReport.

public static Boolean postReport(String url, List<NameValuePair> values) {
    HttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(url);
    try {
        httpPost.setEntity(new UrlEncodedFormEntity(values));
        HttpResponse response = httpClient.execute(httpPost);
        switch(response.getStatusLine().getStatusCode()) {
            case 200:
                Log.e(AnkiDroidApp.TAG, String.format("feedback report posted to %s", url));
                return true;
            default:
                Log.e(AnkiDroidApp.TAG, String.format("feedback report posted to %s message", url));
                Log.e(AnkiDroidApp.TAG, String.format("%d: %s", response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase()));
                break;
        }
    } catch (ClientProtocolException ex) {
        Log.e(AnkiDroidApp.TAG, ex.toString());
    } catch (IOException ex) {
        Log.e(AnkiDroidApp.TAG, ex.toString());
    }
    return false;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) HttpResponse(org.apache.http.HttpResponse) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) IOException(java.io.IOException) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) ClientProtocolException(org.apache.http.client.ClientProtocolException)

Aggregations

ClientProtocolException (org.apache.http.client.ClientProtocolException)83 IOException (java.io.IOException)75 HttpResponse (org.apache.http.HttpResponse)45 HttpPost (org.apache.http.client.methods.HttpPost)33 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)29 HttpClient (org.apache.http.client.HttpClient)28 HttpGet (org.apache.http.client.methods.HttpGet)24 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)20 HttpEntity (org.apache.http.HttpEntity)19 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)19 ArrayList (java.util.ArrayList)18 UnsupportedEncodingException (java.io.UnsupportedEncodingException)17 InputStreamReader (java.io.InputStreamReader)14 NameValuePair (org.apache.http.NameValuePair)13 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)13 InputStream (java.io.InputStream)12 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)11 BufferedReader (java.io.BufferedReader)9 StringEntity (org.apache.http.entity.StringEntity)9 JSONException (org.json.JSONException)9