List of usage examples for org.apache.http.client ClientProtocolException getMessage
public String getMessage()
From source file:com.worthed.googleplus.HttpUtils.java
/** * Send post request./*from ww w . j a v a 2s . com*/ * @param url * @param params * @return It's a error if result start with "Error:". */ public String doPost(String url, List<NameValuePair> params) { HttpClient httpClient = getHttpClient(); /* HTTPPost */ HttpPost httpRequest = new HttpPost(url); String strResult = ERROR_PREFIX; try { /* ? */ httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8)); /* ??? */ HttpResponse httpResponse = httpClient.execute(httpRequest); /* ??200 ok */ if (httpResponse.getStatusLine().getStatusCode() == 200) { /* ? */ strResult = EntityUtils.toString(httpResponse.getEntity()); } else { strResult += httpResponse.getStatusLine().toString(); } } catch (ClientProtocolException e) { strResult += e.getMessage().toString(); e.printStackTrace(); return null; } catch (IOException e) { strResult += e.getMessage().toString(); e.printStackTrace(); return null; } catch (Exception e) { strResult += e.getMessage().toString(); e.printStackTrace(); return null; } Log.w(TAG, strResult); return strResult; }
From source file:es.warp.killthedj.spotify.SpotifyHTTPGet.java
public String get(String query) throws SpotifyQueryNetworkException { String url = SPOTIFY_URL + query; Log.d("SpotifyHTTPGet", "URL: " + url); StringBuilder builder = new StringBuilder(); HttpClient client = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); try {/* w w w . j a v a2 s . c o m*/ HttpResponse response = client.execute(httpGet); if (response.getStatusLine().getStatusCode() != 200) { Log.e("SpotifyHTTPGet", "URL: " + url); Log.e("SpotifyHTTPGet", response.getStatusLine().toString()); throw new SpotifyQueryNetworkException("Didn't get 200 OK"); } BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String line; while ((line = reader.readLine()) != null) { builder.append(line); } return builder.toString(); } catch (ClientProtocolException e) { Log.e("SpotifyHTTPGet", e.getClass().getSimpleName() + ": " + e.getMessage()); throw new SpotifyQueryNetworkException(e); } catch (IOException e) { Log.e("SpotifyHTTPGet", e.getClass().getSimpleName() + ": " + e.getMessage()); throw new SpotifyQueryNetworkException(e); } }
From source file:org.bishoph.oxdemo.util.OXLoginAction.java
@Override protected JSONObject doInBackground(Object... params) { HttpPost httppost = new HttpPost((String) params[0]); try {//from w w w.j a v a 2 s.co m // Add your data List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3); nameValuePairs.add(new BasicNameValuePair("name", (String) params[1])); nameValuePairs.add(new BasicNameValuePair("password", (String) params[2])); nameValuePairs.add(new BasicNameValuePair("client", "OXDemo client")); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); Log.d("OXDemo", "Execute post request " + params[0]); // Execute HTTP Post Request HttpResponse response = httpclient.execute(httppost, localcontext); HttpEntity entity = response.getEntity(); String result = EntityUtils.toString(entity); Log.d("OXDemo", "<<<<<<<\n" + result + "\n\n"); JSONObject jsonObj = new JSONObject(result); return jsonObj; } catch (ClientProtocolException e) { Log.e("OXDemo", e.getMessage()); } catch (IOException e) { Log.e("OXDemo", e.getMessage()); } catch (JSONException e) { Log.e("OXDemo", e.getMessage()); } return null; }
From source file:com.liato.bankdroid.banking.banks.BlekingeTrafiken.java
public Urllib login() throws LoginException, BankException { try {/*w w w . ja va2 s. c o m*/ LoginPackage lp = preLogin(); HttpResponse httpResponse = urlopen.openAsHttpResponse(URL, new StringEntity("{\"cardnr\":" + username + "}"), true); if (httpResponse.getStatusLine().getStatusCode() != 200) { throw new LoginException(res.getText(R.string.invalid_card_number).toString()); } response = EntityUtils.toString(httpResponse.getEntity()); } catch (ClientProtocolException e) { throw new BankException(e.getMessage()); } catch (IOException e) { throw new BankException(e.getMessage()); } return urlopen; }
From source file:com.sourcey.materiallogindemo.MasterActivity.java
private String getJSONUrl(String url, List<NameValuePair> params) { StringBuilder str = new StringBuilder(); HttpClient client = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); try {/*from w w w. j a va 2 s .c o m*/ httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); HttpResponse response = client.execute(httpPost); StatusLine statusLine = response.getStatusLine(); int statusCode = statusLine.getStatusCode(); if (statusCode == 200) { // Download OK HttpEntity entity = response.getEntity(); InputStream content = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(content)); String line; while ((line = reader.readLine()) != null) { str.append(line); } } else { Log.e("Log", "Failed to download file.."); } } catch (ClientProtocolException e) { e.getMessage(); } catch (IOException e) { e.getMessage(); } return str.toString(); }
From source file:com.liato.bankdroid.banking.banks.SvenskaSpel.java
@Override public Urllib login() throws LoginException, BankException { try {//w w w . java 2 s .com LoginPackage lp = preLogin(); response = urlopen.open(lp.getLoginTarget(), lp.getPostData()); if (response.contains("Felaktigt anv")) { throw new LoginException(res.getText(R.string.invalid_username_password).toString()); } } catch (ClientProtocolException e) { throw new BankException(e.getMessage()); } catch (IOException e) { throw new BankException(e.getMessage()); } return urlopen; }
From source file:piramide.multimodal.downloader.client.RestClient.java
private String[] json2list(String url) throws DownloaderException { try {/* w ww . j a va 2 s. c o m*/ final HttpClient client = new DefaultHttpClient(); final HttpResponse response = client.execute(new HttpGet(url)); final InputStream is = response.getEntity().getContent(); final int size = (int) response.getEntity().getContentLength(); final byte[] buffer = new byte[size]; final BufferedInputStream bis = new BufferedInputStream(is); int position = 0; while (position < size) { final int read = bis.read(buffer, position, buffer.length - position); if (read <= 0) break; position += read; } final String strResponse = new String(buffer); final JSONArray arr = new JSONArray(strResponse); final String[] returnValue = new String[arr.length()]; for (int i = 0; i < arr.length(); ++i) returnValue[i] = arr.getString(i); return returnValue; } catch (ClientProtocolException e) { throw new DownloaderException(e.getMessage(), e); } catch (IllegalStateException e) { throw new DownloaderException(e.getMessage(), e); } catch (IOException e) { throw new DownloaderException(e.getMessage(), e); } catch (JSONException e) { throw new DownloaderException(e.getMessage(), e); } }
From source file:com.exquance.jenkins.plugins.conduit.ConduitAPIClient.java
/** * Call the conduit API of Phabricator/*from www. j a va 2s. c o m*/ * @param action Name of the API call * @param params The data to send to Harbormaster * @return The result as a JSONObject * @throws IOException If there was a problem reading the response * @throws ConduitAPIException If there was an error calling conduit */ public JSONObject perform(String action, JSONObject params) throws IOException, ConduitAPIException { CloseableHttpClient client = HttpClientBuilder.create().build(); HttpUriRequest request = createRequest(action, params); HttpResponse response; try { response = client.execute(request); } catch (ClientProtocolException e) { throw new ConduitAPIException(e.getMessage()); } InputStream responseBody = response.getEntity().getContent(); if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { throw new ConduitAPIException(responseBody.toString(), response.getStatusLine().getStatusCode()); } JsonSlurper jsonParser = new JsonSlurper(); return (JSONObject) jsonParser.parse(responseBody); }
From source file:com.liato.bankdroid.banking.banks.AvanzaMini.java
@Override public Urllib login() throws LoginException, BankException { String response = null;//from w w w . jav a2s . c o m try { LoginPackage lp = preLogin(); response = urlopen.open(lp.getLoginTarget(), lp.getPostData()); if (response.contains("Felaktigt") && !response.contains("Logga ut")) { throw new LoginException(res.getText(R.string.invalid_username_password).toString()); } } catch (ClientProtocolException e) { throw new BankException(e.getMessage()); } catch (IOException e) { throw new BankException(e.getMessage()); } return urlopen; }
From source file:com.liato.bankdroid.banking.banks.Jojo.java
public Urllib login() throws LoginException, BankException { try {//from w ww . ja v a 2 s . c o m LoginPackage lp = preLogin(); response = urlopen.open(lp.getLoginTarget(), lp.getPostData()); if (response.contains("Kortnumret finns inte.")) { throw new LoginException(res.getText(R.string.invalid_card_number).toString()); } } catch (ClientProtocolException e) { throw new BankException(e.getMessage()); } catch (IOException e) { throw new BankException(e.getMessage()); } return urlopen; }