Codota Logo
BasicResponseHandler
Code IndexAdd Codota to your IDE (free)

How to use
BasicResponseHandler
in
org.apache.http.impl.client

Best Java code snippets using org.apache.http.impl.client.BasicResponseHandler (Showing top 20 results out of 540)

Refine searchRefine arrow

  • HttpClient
  • DefaultHttpClient
  • HttpPost
  • HttpGet
  • JSONObject
  • Common ways to obtain BasicResponseHandler
private void myMethod () {
BasicResponseHandler b =
  • Codota Iconnew BasicResponseHandler()
  • Smart code suggestions by Codota
}
origin: stackoverflow.com

HttpClient httpclient = new DefaultHttpClient();  
HttpGet request = new HttpGet(URL + q);  
request.addHeader("deviceId", deviceId);  
ResponseHandler<string> handler = new BasicResponseHandler();  
try {  
  result = httpclient.execute(request, handler);  
} catch (ClientProtocolException e) {  
  e.printStackTrace();  
  e.printStackTrace();  
httpclient.getConnectionManager().shutdown();  
Log.i(tag, result);  
origin: robolectric/robolectric

@Test
public void shouldSupportBasicResponseHandlerHandleResponse() throws Exception {
 FakeHttp.addPendingHttpResponse(200, "OK", new BasicHeader("Content-Type", "text/plain"));
 DefaultHttpClient client = new DefaultHttpClient();
 HttpResponse response = client.execute(new HttpGet("http://www.nowhere.org"));
 assertThat(((HttpUriRequest) FakeHttp.getSentHttpRequest(0)).getURI())
   .isEqualTo(URI.create("http://www.nowhere.org"));
 Assert.assertNotNull(response);
 String responseStr = new BasicResponseHandler().handleResponse(response);
 Assert.assertEquals("OK", responseStr);
}
origin: chanjarster/weixin-java-tools

  + "&secret=" + wxMpConfigStorage.getSecret();
try {
 HttpGet httpGet = new HttpGet(url);
 if (httpProxy != null) {
  RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build();
  httpGet.setConfig(config);
 String resultContent = new BasicResponseHandler().handleResponse(response);
 WxError error = WxError.fromJson(resultContent);
 if (error.getErrorCode() != 0) {
origin: apache/cloudstack

HttpGet get_request = new HttpGet("https://" + _ip + s_apiUri + queryString);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
try {
  responseBody = s_httpclient.execute(get_request, responseHandler);
} catch (IOException e) {
  throw new ExecutionException(e.getMessage());
HttpPost post_request = new HttpPost("https://" + _ip + s_apiUri);
try {
  post_request.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
} catch (UnsupportedEncodingException e) {
  throw new ExecutionException(e.getMessage());
ResponseHandler<String> responseHandler = new BasicResponseHandler();
try {
  responseBody = s_httpclient.execute(post_request, responseHandler);
} catch (IOException e) {
  throw new ExecutionException(e.getMessage());
origin: stackoverflow.com

 public static boolean sendJSONtoBLX(String path, JSONObject json)
    throws Exception {
  DefaultHttpClient httpclient = new DefaultHttpClient();
  HttpPost httpost = new HttpPost(path);
  StringEntity se = new StringEntity(json.toString());
  httpost.setEntity(se);
  httpost.setHeader("Accept", "application/json");
  httpost.setHeader("Content-type", "application/json");
  @SuppressWarnings("rawtypes")
  ResponseHandler responseHandler = new BasicResponseHandler();
  @SuppressWarnings("unchecked")
  String response = httpclient.execute(httpost, responseHandler);
  JSONObject jsonResponse = new JSONObject(response);
  String serverResponse = jsonResponse.getString("success");

  if (serverResponse.equals("true")) {
    return true;
  } else {
    return false;
  }
}
origin: com.atlassian.plugins/atlassian-connect-integration-tests-support

  protected void dismissHelpTip(String tipId) throws Exception {
    HttpPost request = new HttpPost(baseUrl + "/rest/helptips/1.0/tips");
    request.setEntity(new StringEntity(new JSONObject(ImmutableMap.<String, Object>of("id", tipId)).toString(), ContentType.APPLICATION_JSON));
    userRequestSender.sendRequestAsUser(request, new BasicResponseHandler(), defaultUsername, defaultPassword);
  }
}
origin: stackoverflow.com

HttpClient client = new DefaultHttpClient();
 String responseBody;
 JSONObject jsonObject = new JSONObject();
 try{
   HttpPost post = new HttpPost(WebService_URL);
   jsonObject.put("field1", ".........");
   jsonObject.put("field2", ".........");
   StringEntity se = new StringEntity(jsonObject.toString());  
   post.setEntity(se);
   post.setHeader(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
   post.setHeader("Content-type", "application/json");
   Log.e("webservice request","executing");
   ResponseHandler responseHandler = new BasicResponseHandler();
   responseBody = client.execute(post, responseHandler);
   /* 
    * You can work here on your responseBody
    * if it's a simple String or XML/JSON response
    */
 }
 catch (Exception e) {
   e.printStackTrace();
 }
origin: stackoverflow.com

 public static HttpResponse makeRequest(String path, Map params) throws Exception 
{
  //instantiates httpclient to make request
  DefaultHttpClient httpclient = new DefaultHttpClient();

  //url with the post data
  HttpPost httpost = new HttpPost(path);

  //convert parameters into JSON object
  JSONObject holder = getJsonObjectFromMap(params);

  //passes the results to a string builder/entity
  StringEntity se = new StringEntity(holder.toString());

  //sets the post request as the resulting string
  httpost.setEntity(se);
  //sets a request header so the page receving the request
  //will know what to do with it
  httpost.setHeader("Accept", "application/json");
  httpost.setHeader("Content-type", "application/json");

  //Handles what is returned from the page 
  ResponseHandler responseHandler = new BasicResponseHandler();
  return httpclient.execute(httpost, responseHandler);
}
origin: stackoverflow.com

 DefaultHttpClient httpclient = new DefaultHttpClient();
  HttpPost httpost = new HttpPost(url);

  //Firstly declare & create a json object from the desired json as a whole.

/* How to create Json*/
JSONObject jObjectData = new JSONObject();


  // Create Json Object using Facebook Data
  jObjectData.put("method", "startSession");

ArrayList<String> list = new ArrayList<String>();
  list.add("email");
  list.add("testmail@test.it");
etc... ....
  JSONArray jsArray = new JSONArray(list);
   jObjectData.put("params", jsArray);

  StringEntity stringEntity = new StringEntity(jObjectData.toString());
  httpost.setEntity(stringEntity);
  httpost.setHeader("Accept", "application/json");
  httpost.setHeader("Content-type", "application/json");

  ResponseHandler responseHandler = new BasicResponseHandler();
  response = httpclient.execute(httpost, responseHandler);
origin: stackoverflow.com

 String path = null;
try{
    HttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost("http://192.168.1.25/userdatabase/include/GetSource.php");
    HttpResponse response = httpClient.execute(httpPost);
    BasicResponseHandler handler = new BasicResponseHandler();
    String data = handler.handleResponse(response).replace('"','\'');  //edited this line
    JSONArray ja = new JSONArray(data); //added this line
    JSONObject jObj = ja.getJSONObject(0); //edited this line
    path= jObj.getString("sources");

} catch (Exception e) {
  Log.e("Log_tag", "Error converting result" + e.toString());
}
origin: stackoverflow.com

 public String getJson(String url) {
 try {
    DefaultHttpClient defaultHttpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(url);
    httpost.setHeader("Accept", "application/json");
    httpost.setHeader("Content-type", "application/json");

    ResponseHandler responseHandler = new BasicResponseHandler();
    Object resp = defaultHttpClient.execute(httpPost, responseHandler);
    String json =  resp.toString();
    // create a object here if you want
    JSONObject obj = new JSONObject(json);
    return json;        
  } catch (Exception ex) {
     Toast.makeText(getApplicationContext(), "ERROR : " + ex, Toast.LENGTH_LONG).show();
    return null;
  }

}
origin: stackoverflow.com

JSONObject googleMapResponse = new JSONObject(ANDROID_HTTP_CLIENT.execute(new HttpGet(googleMapUrl),
    new BasicResponseHandler()));
JSONArray results = (JSONArray) googleMapResponse.get("results");
for (int i = 0; i < results.length(); i++)
  if (result.has("address_components"))
    JSONArray addressComponents = result.getJSONArray("address_components");
origin: stackoverflow.com

 String url = "http://www.dw.com/ur/مارشل-لاء-کا-مطالبہ-سازش-یا-خواہش؟/a-19395440?maca=urd-rss-urd-all-1497-xml-mrss";
url = StringUtils.replaceEach(URLEncoder.encode(url, "UTF-8"), new String[]{"+", "*", "%7E"}, new String[]{"%20", "%2A", "~"})
HttpClient httpClient = HttpClientBuilder.create().build();
HttpGet httpget = new HttpGet(url);
HttpResponse response = httpClient.execute(httpget);
BasicResponseHandler bh = new BasicResponseHandler();
String res = new String(bh.handleResponse(response));
Document doc = Jsoup.parse(res);
origin: com.atlassian.plugins/atlassian-connect-integration-tests-support

public void setEnabled(String appKey, boolean enabled) throws Exception {
  HttpPut request = new HttpPut(UpmTokenRequestor.getUpmPluginResource(baseUrl, appKey));
  request.setHeader("Content-Type", "application/vnd.atl.plugins.plugin+json");
  String requestBody = new JSONObject(ImmutableMap.<String, Object>of("enabled", Boolean.toString(enabled))).toString();
  request.setEntity(new StringEntity(requestBody));
  request.setHeader("Accept", "application/json");
  ResponseHandler<String> responseHandler = new BasicResponseHandler();
  userRequestSender.sendRequestAsUser(request, responseHandler, defaultUsername, defaultPassword);
}
origin: te-con/ehour

  @Override
  public Optional<String> getLatestVersionNumber(String currentVersion, boolean isScheduled) {
    HttpClient client = HttpClientBuilder.create().build();

    try {
      LOGGER.info("Fetching latest version number of eHour release from " + versionUrl);

      HttpGet request = new HttpGet(versionUrl);
      request.setHeader("User-Agent", String.format("%s eHour update client v%s", isScheduled ? "Scheduled" : "Bootstrap", currentVersion));

      BasicResponseHandler responseHandler = new BasicResponseHandler();
      String response = client.execute(request, responseHandler);

      return Optional.of(response);
    } catch (Exception e) {
      LOGGER.info("Failed to retrieve latest published eHour version: " + e.getMessage());

    }

    return Optional.absent();
  }
}
origin: stackoverflow.com

 HttpParams params = new BasicHttpParams();
params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
HttpClient httpClient = new DefaultHttpClient(params);
HttpPost httpPost = new HttpPost(your website);

List<NameValuePair> entityParams = new ArrayList<NameValuePair>();
entityParams.add(new BasicNameValuePair("action", "postcomment"));
entityParams.add(new BasicNameValuePair("app_id", com.appbuilder.sdk.android.Statics.appId));
entityParams.add(new BasicNameValuePair("message", message1));
entityParams.add(new BasicNameValuePair("message2", message2));

httpPost.setEntity(new UrlEncodedFormEntity(entityParams, "utf-8"));

String resp = httpClient.execute(httpPost, new BasicResponseHandler());
origin: stackoverflow.com

CommonsHttpOAuthConsumer consumer = null;
 consumer = new CommonsHttpOAuthConsumer(CONSUMER_KEY,CONSUMER_SECRET);
 consumer.setTokenWithSecret(oaut_token, tokenSecret);
 // Use the apache method instead - probably should make this part persistent until
 // you are done issuing API calls    
 HttpParams parameters = new BasicHttpParams();
 HttpProtocolParams.setVersion(parameters, HttpVersion.HTTP_1_1);
 HttpProtocolParams.setContentCharset(parameters, HTTP.DEFAULT_CONTENT_CHARSET);
 HttpProtocolParams.setUseExpectContinue(parameters, false);
 HttpConnectionParams.setTcpNoDelay(parameters, true);
 HttpConnectionParams.setSocketBufferSize(parameters, 8192);
 HttpClient httpClient = new DefaultHttpClient();
 SchemeRegistry schReg = new SchemeRegistry();
 schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
 ClientConnectionManager tsccm = new ThreadSafeClientConnManager(parameters, schReg);
 httpClient = new DefaultHttpClient(tsccm, parameters);
 HttpGet get = new HttpGet(targetURL); 
 // sign the request
 consumer.sign(get);
 // send the request & get the response (probably a json object, but whatever)
 String response = httpClient.execute(get, new BasicResponseHandler());
 // shutdown the connection manager - last bit of the apache code 
 httpClient.getConnectionManager().shutdown();
 //Do whatever you want with the returned info 
 JSONObject jsonObject = new JSONObject(response);
origin: kongzhidea/pay

HttpClient httpClient = new DefaultHttpClient();
httpClient.getParams().setParameter(
    CoreConnectionPNames.CONNECTION_TIMEOUT, 10000);
httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,
    10000);
try {
  HttpGet httpGet = new HttpGet(uri);
  logger.info("executing request " + httpGet.getURI());
  ResponseHandler<String> responseHandler = new BasicResponseHandler();
  responseBody = httpClient.execute(httpGet, responseHandler);
  logger.info(responseBody);
} catch (ClientProtocolException e) {
origin: stackoverflow.com

DefaultHttpClient  httpclient = getClient();
HttpPost httppost = new HttpPost("complete address");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(4);//number should be the amount of parameters 
 nameValuePairs.add(new BasicNameValuePair("param_name", "param_value"));
 nameValuePairs.add(new BasicNameValuePair("param_name", "param_value"));
 try {
   httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
   HttpResponse response = httpclient.execute(httppost);
   HttpEntity ht = response.getEntity();
   BasicResponseHandler myHandler = new BasicResponseHandler();
       String endResult = "";
     endResult = myHandler.handleResponse(response); 
     System.out.println("endResuilt*** = "+endResult);
     dataStream = endResult;
   }catch(Exception e){
     //Catch the Exception
   }
origin: com.atlassian.plugins/atlassian-connect-integration-tests-support

  public boolean isModuleInstalled(String addonKey, String moduleKey) throws Exception {
    final HttpGet request = new HttpGet(baseUrl + "/rest/remoteplugintest/1/addon-control/is-module-installed?addonKey=" + addonKey + "&moduleKey=" + moduleKey);
    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    String response = userRequestSender.sendRequestAsUser(request, responseHandler, defaultUsername, defaultPassword);
    return Boolean.parseBoolean(response);
  }
}
org.apache.http.impl.clientBasicResponseHandler

Javadoc

A ResponseHandler that returns the response body as a String for successful (2xx) responses. If the response code was >= 300, the response body is consumed and an HttpResponseException is thrown. If this is used with org.apache.http.client.HttpClient#execute( * org.apache.http.client.methods.HttpUriRequest, ResponseHandler),

Most used methods

  • <init>
  • handleResponse
    Returns the response body as a String if the response was successful (a 2xx status code). If no resp

Popular in Java

  • Creating JSON documents from java classes using gson
  • getExternalFilesDir (Context)
  • orElseThrow (Optional)
  • setContentView (Activity)
  • MalformedURLException (java.net)
    Thrown to indicate that a malformed URL has occurred. Either no legal protocol could be found in a s
  • URI (java.net)
    Represents a Uniform Resource Identifier (URI) reference. Aside from some minor deviations noted bel
  • Collection (java.util)
    Collection is the root of the collection hierarchy. It defines operations on data collections and t
  • UUID (java.util)
    UUID is an immutable representation of a 128-bit universally unique identifier (UUID). There are mul
  • HttpServletRequest (javax.servlet.http)
    Extends the javax.servlet.ServletRequest interface to provide request information for HTTP servlets.
  • JTable (javax.swing)
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now