List of usage examples for org.apache.http.client.methods HttpGet toString
public String toString()
From source file:org.easit.core.controllers.signin.SigninController.java
/** * Internal helpers/*from ww w . j a v a2s .co m*/ * Return with the * @param request * @return * @throws Exception */ private String getGpiiToken(String accessToken) throws Exception { HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet( environment.getProperty("flowManager.url") + environment.getProperty("flowManager.gpii_token")); // add the access token to the request header request.addHeader("Authorization", "Bearer " + accessToken); HttpResponse response = client.execute(request); //NOT Correct answer if (response.getStatusLine().getStatusCode() != 200) { logger.info("ERROR:"); logger.info("URL target" + environment.getProperty("flowManager.url") + environment.getProperty("flowManager.gpii_token")); logger.info(request.toString()); for (Header header : request.getAllHeaders()) { logger.info(header.getName() + " : " + header.getValue()); } throw new Exception("Failed : HTTP error code : " + response.getStatusLine().getStatusCode()); } //Correct answer BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuffer result = new StringBuffer(); String line = ""; while ((line = rd.readLine()) != null) { result.append(line); } logger.info("GPII:" + result); //Extract the Gpii token from the response JSONObject json = new JSONObject(result.toString()); Map<String, String> output = new HashMap<String, String>(); CoreUtils.parse(json, output); return output.get("gpii_token"); }
From source file:fridgegameinstaller.installation.java
public String getLatestModpackVersion() { CloseableHttpClient httpclient = HttpClients.createDefault(); HttpGet httpGet = new HttpGet("http://api.fridgegame.com/version/"); JSONObject json;// w ww.ja v a 2 s . co m String ver = ""; try { CloseableHttpResponse response1 = httpclient.execute(httpGet); System.out.println(httpGet.toString()); System.out.println(response1.getStatusLine()); BufferedReader br = new BufferedReader(new InputStreamReader(response1.getEntity().getContent())); String a; String output = ""; while ((a = br.readLine()) != null) { output += a + "\n"; } System.out.println(output); try { json = new JSONObject(output); ver = json.getString("version"); } catch (JSONException e) { e.printStackTrace(); mainFrame.errorMsg( "An error occured while reading latest Modpack version.More information in the log", "Error"); mainFrame.setFormToPostInstallation(); } } catch (IOException e) { e.printStackTrace(); mainFrame.errorMsg("An error occured.More information in the log", "Error"); mainFrame.setFormToPostInstallation(); } System.out.println(ver); return ver; }
From source file:com.urs.triptracks.TripUploader.java
boolean uploadOneTrip(long currentTripId) { boolean result = false; String postBodyData;//w w w . j ava 2 s. c o m try { postBodyData = getPostData(currentTripId); } catch (JSONException e) { e.printStackTrace(); return result; } Log.v("codedPostData", postBodyData); HttpClient client = new DefaultHttpClient(); //final String postUrl = "https://fdotrts.ursokr.com/TripTracker_WCF_Rest_Service_ursokr/TripTracker.svc/SaveTrip"; final String postUrl1 = "https://fdotrts.ursokr.com/TripTracker_WCF_Rest_Service_ursokr/TripTracker.svc/OpenConnTest"; HttpGet postRequest1 = new HttpGet(postUrl1); Log.v("PostURLOPENCONN:", postUrl1); Log.v("PostURLOPENCONN:", postRequest1.toString()); postRequest1.setHeader("Accept", "application/json"); postRequest1.setHeader("Content-type", "application/json; charset=utf-8"); try { StringEntity str1 = new StringEntity(postBodyData, HTTP.UTF_8); //postRequest1.setEntity(str1); HttpResponse response1 = client.execute(postRequest1); HttpEntity entity1 = response1.getEntity(); String responseString1 = getASCIIContentFromEntity(entity1); Log.v("httpResponseHema1", responseString1); JSONObject responseData1 = new JSONObject(responseString1); Log.v("responseDataHema1:", responseData1.toString()); /*if (responseData.getString("Result").equals("Trip data was saved")) { mDb.open(); mDb.updateTripStatus(currentTripId, TripData.STATUS_SENT); mDb.close(); result = true; }*/ //if (responseData1.getString("Result").equals("Web service contacted and responded")) { if (responseData1.getString("Result") .startsWith(" Success connecting to the database via the webservice")) { final String postUrl2 = "https://fdotrts.ursokr.com/TripTracker_WCF_Rest_Service_ursokr/TripTracker.svc/SaveTrip"; HttpPost postRequest2 = new HttpPost(postUrl2); Log.v("PostURL2:", postUrl2); Log.v("PostRequest2:", postRequest2.toString()); postRequest2.setHeader("Accept", "application/json"); postRequest2.setHeader("Content-type", "application/json; charset=utf-8"); try { Log.v("postBodyData:", postBodyData); StringEntity str2 = new StringEntity(postBodyData, HTTP.UTF_8); postRequest2.setEntity(str2); HttpResponse response2 = client.execute(postRequest2); HttpEntity entity2 = response2.getEntity(); String responseString2 = getASCIIContentFromEntity(entity2); Log.v("httpResponseHema2", responseString2); JSONObject responseData2 = new JSONObject(responseString2); Log.v("responseDataHema2:", responseData2.toString()); if (responseData2.getString("Result").equals("Trip data was saved")) { mDb.open(); mDb.updateTripStatus(currentTripId, TripData.STATUS_SENT); mDb.close(); result = true; } } catch (IllegalStateException e) { e.printStackTrace(); return false; } catch (IOException e) { e.printStackTrace(); return false; } catch (JSONException e) { e.printStackTrace(); Log.e("Hema_log_tag2nd", "Error parsing data " + e.toString()); Log.e("Hema_log_tag2nd", "Failed data was:\n" + result); return false; } return result; } else { Toast.makeText(mCtx.getApplicationContext(), "Couldn't connect to the webservice.", Toast.LENGTH_LONG).show(); } } catch (IllegalStateException e) { e.printStackTrace(); return false; } catch (IOException e) { e.printStackTrace(); return false; } catch (JSONException e) { e.printStackTrace(); Log.e("Hema_log_tag1st", "1st step Error parsing data " + e.toString()); Log.e("Hema_log_tag1st", "1st step Failed data was:\n" + result); return false; } return result; }
From source file:fridgegameinstaller.installation.java
public void installShader() { progmsg.setText("Installing shader..."); CloseableHttpClient httpclient = HttpClients.createDefault(); HttpGet httpGet = new HttpGet("http://api.fridgegame.com/version/"); JSONObject json;/*w w w . ja v a2 s .com*/ String shader_dl_url = ""; try { CloseableHttpResponse response1 = httpclient.execute(httpGet); System.out.println(httpGet.toString()); System.out.println(response1.getStatusLine()); BufferedReader br = new BufferedReader(new InputStreamReader(response1.getEntity().getContent())); String a; String output = ""; while ((a = br.readLine()) != null) { output += a + "\n"; } System.out.println(output); try { json = new JSONObject(output); shader_dl_url = json.getString("shader_dl_url"); } catch (JSONException e) { e.printStackTrace(); mainFrame.errorMsg( "An error occured while reading latest Modpack version.More information in the log", "Error"); mainFrame.setFormToPostInstallation(); } } catch (IOException e) { e.printStackTrace(); mainFrame.errorMsg("An error occured.More information in the log", "Error"); mainFrame.setFormToPostInstallation(); } File shaderfile = new File(mcloc + "/mods/shader.jar"); try { URL shaderdlurl = new URL(shader_dl_url); org.apache.commons.io.FileUtils.copyURLToFile(shaderdlurl, shaderfile); } catch (Exception e) { e.printStackTrace(); mainFrame.errorMsg("An error occured while downloading mods.More information in the log", "Error"); mainFrame.setFormToPostInstallation(); } }
From source file:com.couchbase.jdbc.core.ProtocolImpl.java
public CBResultSet query(CBStatement statement, String sql) throws SQLException { Instance instance = getNextEndpoint(); @SuppressWarnings("unchecked") Map<String, String> parameters = new HashMap(); parameters.put(STATEMENT, sql);/* ww w .j ava 2 s .c o m*/ addOptions(parameters); List<NameValuePair> parms = new ArrayList<NameValuePair>(); for (String parameter : parameters.keySet()) { parms.add(new BasicNameValuePair(parameter, parameters.get(parameter))); } while (true) { String url = instance.getEndpointURL(ssl); logger.trace("Using endpoint {}", url); URI uri = null; try { uri = new URIBuilder(url).addParameters(parms).build(); } catch (URISyntaxException ex) { logger.error("Invalid request {}", url); } HttpGet httpGet = new HttpGet(uri); httpGet.setHeader("Accept", "application/json"); logger.trace("Get request {}", httpGet.toString()); try { CloseableHttpResponse response = httpClient.execute(httpGet); return new CBResultSet(statement, handleResponse(sql, response)); } catch (ConnectTimeoutException cte) { logger.trace(cte.getLocalizedMessage()); // this one failed, lets move on invalidateEndpoint(instance); // get the next one instance = getNextEndpoint(); if (instance == null) { throw new SQLException("All endpoints have failed, giving up"); } } catch (IOException ex) { logger.error("Error executing query [{}] {}", sql, ex.getMessage()); throw new SQLException("Error executing update", ex.getCause()); } } }
From source file:sonata.kernel.vimadaptor.wrapper.openstack.javastackclient.JavaStackCore.java
public synchronized HttpResponse getStackTemplate(String stackName, String stackId) throws IOException, URISyntaxException { HttpResponseFactory factory = new DefaultHttpResponseFactory(); HttpClient httpclient = HttpClientBuilder.create().build(); HttpGet getStackTemplate = null; HttpResponse response = null;// w w w . j av a2 s. c om if (isAuthenticated) { URIBuilder builder = new URIBuilder(); String path = String.format("/%s/%s/stacks/%s/%s/template", Constants.HEAT_VERSION.toString(), this.tenant_id, stackName, stackId); builder.setScheme("http").setHost(endpoint).setPort(Integer.parseInt(Constants.HEAT_PORT.toString())) .setPath(path); URI uri = builder.build(); getStackTemplate = new HttpGet(uri); getStackTemplate.addHeader(Constants.AUTHTOKEN_HEADER.toString(), this.token_id); Logger.debug("Request: " + getStackTemplate.toString()); response = httpclient.execute(getStackTemplate); int status_code = response.getStatusLine().getStatusCode(); Logger.debug("Response: " + response.toString()); return (status_code == 200) ? response : factory.newHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, status_code, "Get Template Failed with Status: " + status_code), null); } else { throw new IOException("You must Authenticate before issuing this request, please re-authenticate. "); } }
From source file:org.sdntest.app.SDNTest.java
private boolean flowAllowed() { // get login info from file // TODO: get from somewhere else, or setup certs BufferedReader br = null;//from w ww. ja v a2s. c o m String uname; String password; try { br = new BufferedReader(new FileReader(GLOBUS_LOGIN_FILE)); uname = br.readLine(); password = br.readLine(); } catch (IOException e) { log.info("Error reading globus login file: {}", GLOBUS_LOGIN_FILE); return false; } finally { try { if (br != null) { br.close(); } } catch (IOException ex) { log.info("Error closing globus login file"); } } if (uname == null || password == null) { log.info("Error: could not get globus login from file"); return false; } else { log.info("Got globus login un: {}, pw: {}", uname, password); } // use login info to get authentication token UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(uname, password); CloseableHttpClient httpclient = HttpClientBuilder.create().build(); HttpGet authGet = new HttpGet(GLOBUS_AUTH_URL); try { authGet.addHeader(new BasicScheme().authenticate(credentials, authGet)); } catch (AuthenticationException e1) { e1.printStackTrace(); } authGet.addHeader("User-Agent", "onos"); log.info(authGet.toString()); CloseableHttpResponse response1; try { response1 = httpclient.execute(authGet); } catch (ClientProtocolException e) { e.printStackTrace(); return false; } catch (IOException e) { e.printStackTrace(); return false; } String authTok = ""; try { log.info(response1.toString()); String resStr = EntityUtils.toString(response1.getEntity()); log.info(resStr); JSONParser jsonParser = new JSONParser(); JSONObject jsonObject = (JSONObject) jsonParser.parse(resStr); authTok = (String) jsonObject.get("access_token"); } catch (IOException e) { e.printStackTrace(); return false; } catch (ParseException e) { e.printStackTrace(); return false; } catch (org.json.simple.parser.ParseException e) { e.printStackTrace(); } finally { try { response1.close(); } catch (IOException e) { e.printStackTrace(); } } log.info("Token: {}", authTok); return true; }
From source file:fridgegameinstaller.installation.java
public void install(int mb) { //check .minecraft exists File mclocf = new File(mcloc); if (!mclocf.isDirectory()) { System.out.println("wrong mc loc"); mainFrame.errorMsg("Could not find minecraft directory.", "Error"); mainFrame.setFormToPostInstallation(); } else {//from w w w . j a va2 s .c o m progmsg.setText("Checking release 1.6.4..."); //Check 1.6.4 Version exists File v164 = new File(mcloc + "/versions/1.6.4"); if (!v164.exists()) { mainFrame.errorMsg( "Could not find release 1.6.4.Start Minecraft with version 1.6.4 before installing Fridgegame.", "Error"); mainFrame.setFormToPostInstallation(); } else { progmsg.setText("Setting up Fridgegame environment..."); prgbar.setValue(2); //creating Fridgegame version folder File vfg = new File(mcloc + "/versions/Fridgegame"); vfg.mkdir(); //copy 1.6.4.jar File v164jar = new File(mcloc + "/versions/1.6.4/1.6.4.jar"); File vfgjar = new File(mcloc + "/versions/Fridgegame/Fridgegame.jar"); try { copyFolder(v164jar, vfgjar); } catch (IOException e) { e.printStackTrace(); mainFrame.errorMsg("An error occured while dublicating 1.6.4.jar.More information in the log", "Error"); mainFrame.setFormToPostInstallation(); } progmsg.setText("Setting up natives..."); prgbar.setValue(5); File v164n = new File(mcloc + "/versions/1.6.4/1.6.4-natives"); File vfgn = new File(mcloc + "/versions/Fridgegame/Fridgegame-natives"); try { copyFolder(v164n, vfgn); } catch (IOException e) { e.printStackTrace(); mainFrame.errorMsg("An error occured while dublicating natives.More information in the log", "Error"); mainFrame.setFormToPostInstallation(); } //init JSON progmsg.setText("Setting up basic json..."); prgbar.setValue(7); File vfgjson = new File(mcloc + "/versions/Fridgegame/Fridgegame.json"); //config json try { MCJsonConf.getJson(mcloc + "/versions/Fridgegame/Fridgegame.json", mb); } catch (IOException e) { e.printStackTrace(); mainFrame.errorMsg( "An error occured while getting json information.More information in the log", "Error"); mainFrame.setFormToPostInstallation(); } //get json obj prgbar.setValue(10); progmsg.setText("Fetshing information..."); CloseableHttpClient httpclient = HttpClients.createDefault(); HttpGet httpGet = new HttpGet("http://api.fridgegame.com/version/"); JSONObject json; String path = ""; String scala_library_version = ""; String scala_library_dl_url = ""; String scala_compiler_version = ""; String scala_compiler_dl_url = ""; String forge_version = ""; String forge_dl_url = ""; try { CloseableHttpResponse response1 = httpclient.execute(httpGet); System.out.println(httpGet.toString()); System.out.println(response1.getStatusLine()); BufferedReader br = new BufferedReader( new InputStreamReader(response1.getEntity().getContent())); String a; String output = ""; while ((a = br.readLine()) != null) { output += a + "\n"; } System.out.println(output); try { json = new JSONObject(output); path = json.getString("path"); scala_library_version = json.getString("scala_library_version"); scala_library_dl_url = json.getString("scala_library_dl_url"); scala_compiler_version = json.getString("scala_compiler_version"); scala_compiler_dl_url = json.getString("scala_compiler_dl_url"); forge_version = json.getString("forge_version"); forge_dl_url = json.getString("forge_dl_url"); } catch (JSONException e) { e.printStackTrace(); mainFrame.errorMsg( "An error occured while fetshing information from server.More information in the log", "Error"); mainFrame.setFormToPostInstallation(); } } catch (Exception e) { e.printStackTrace(); mainFrame.errorMsg("An error occured.More information in the log", "Error"); mainFrame.setFormToPostInstallation(); } //scala setup progmsg.setText("Checking for latest scala lib..."); progmsg.setText("Downloading and installing scala lib..."); prgbar.setValue(15); mainFrame.repaint(); File scalalang = new File(mcloc + "/libraries/org/scala-lang"); scalalang.mkdir(); File scalalibdir = new File(mcloc + "/libraries/org/scala-lang/scala-library"); scalalibdir.mkdir(); File scalalibverdir = new File( mcloc + "/libraries/org/scala-lang/scala-library/" + scala_library_version); scalalibverdir.mkdir(); File scalalib = new File(mcloc + "/libraries/org/scala-lang/scala-library/" + scala_library_version + "/scala-library-" + scala_library_version + ".jar"); //################## try { URL scalalibdlurl = new URL(scala_library_dl_url); org.apache.commons.io.FileUtils.copyURLToFile(scalalibdlurl, scalalib); } catch (Exception e) { e.printStackTrace(); mainFrame.errorMsg( "An error occured while downloading scala library.More information in the log", "Error"); mainFrame.setFormToPostInstallation(); } progmsg.setText("Checking for latest scala compiler..."); prgbar.setValue(30); progmsg.setText("Downloading and installing scala compiler..."); File scalacomdir = new File(mcloc + "/libraries/org/scala-lang/scala-compiler"); scalacomdir.mkdir(); File scalacomverdir = new File( mcloc + "/libraries/org/scala-lang/scala-compiler/" + scala_compiler_version); scalacomverdir.mkdir(); File scalacom = new File(mcloc + "/libraries/org/scala-lang/scala-compiler/" + scala_compiler_version + "/scala-compiler-" + scala_compiler_version + ".jar"); try { URL scalacomdlurl = new URL(scala_compiler_dl_url); org.apache.commons.io.FileUtils.copyURLToFile(scalacomdlurl, scalacom); } catch (Exception e) { e.printStackTrace(); mainFrame.errorMsg( "An error occured while downloading scala compiler.More information in the log", "Error"); mainFrame.setFormToPostInstallation(); } prgbar.setValue(50); progmsg.setText("Checking for latest Minecraft Forge..."); progmsg.setText("Downloading and installing Minecraft Forge..."); File mcfidir1 = new File(mcloc + "/libraries/net/minecraftforge"); File mcfidir2 = new File(mcloc + "/libraries/net/minecraftforge/minecraftforge"); File mcfidir3 = new File(mcloc + "/libraries/net/minecraftforge/minecraftforge/"); File mcfidir4 = new File(mcloc + "/libraries/net/minecraftforge/minecraftforge/" + forge_version); mcfidir1.mkdir(); mcfidir2.mkdir(); mcfidir3.mkdir(); mcfidir4.mkdir(); File mcfidir = new File(mcloc + "/libraries/net/minecraftforge/minecraftforge/" + forge_version + "/minecraftforge-" + forge_version + ".jar"); try { URL forgedlurl = new URL(forge_dl_url); org.apache.commons.io.FileUtils.copyURLToFile(forgedlurl, mcfidir); } catch (Exception e) { e.printStackTrace(); mainFrame.errorMsg( "An error occured while downloading Minecraft Forge.More information in the log", "Error"); mainFrame.setFormToPostInstallation(); } File fgtemp = new File(mcloc + "/fgtemp"); fgtemp.mkdir(); prgbar.setValue(65); progmsg.setText("Downloading mods(may take a while)..."); File fgzipfile = new File(mcloc + "/fgtemp/fg.zip"); try { URL fgzipdlurl = new URL(path); org.apache.commons.io.FileUtils.copyURLToFile(fgzipdlurl, fgzipfile); } catch (Exception e) { e.printStackTrace(); mainFrame.errorMsg("An error occured while downloading mods.More information in the log", "Error"); mainFrame.setFormToPostInstallation(); } progmsg.setText("Installing mods..."); File mclocfile = new File(mcloc); prgbar.setValue(85); File mclocfilea = new File(mcloc); try { Charset CP866 = Charset.forName("CP866"); ZipFile fgzipa = new ZipFile(mcloc + "/fgtemp/fg.zip", CP866); unzip(fgzipa, mclocfilea); } catch (IOException e) { e.printStackTrace(); } if (fgtemp.exists()) { try { deletedir(fgtemp); } catch (IOException e) { e.printStackTrace(); mainFrame.errorMsg("An error occured while deleting temps.More information in the log", "Error"); mainFrame.setFormToPostInstallation(); } } } } }
From source file:com.fhc25.percepcion.osiris.mapviewer.common.restutils.RestClient.java
/** * Executes the requests.// www .j av a 2 s . c om * * @param method the type of method (POST, GET, DELETE, PUT). * @param url the url of the request. * @param headers the headers to include. * @param params the params to include (if any) * @param listener a listener for callbacks. * @throws Exception */ public static void Execute(final RequestMethod method, final String url, final List<NameValuePair> headers, final List<NameValuePair> params, final RestListener listener) throws Exception { new Thread() { @Override public void run() { switch (method) { case GET: { // add parameters String combinedParams = ""; if (params != null) { if (!params.isEmpty()) { combinedParams += "?"; } for (NameValuePair p : params) { String paramString = ""; try { paramString = p.getName() + "=" + URLEncoder.encode(p.getValue(), HTTP.DEFAULT_CONTENT_CHARSET); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } if (combinedParams.length() > 1) combinedParams += "&" + paramString; else combinedParams += paramString; } } HttpGet request = new HttpGet(url + combinedParams); // add headers if (headers != null) { for (NameValuePair h : headers) request.addHeader(h.getName(), h.getValue()); } executeRequest(request, url, listener); break; } case POST: { HttpPost request = new HttpPost(url); // add headers if (headers != null) { for (NameValuePair h : headers) request.addHeader(h.getName(), h.getValue()); } if (params != null) { try { if (params.get(0).getName() == "json") { se = new StringEntity(params.get(0).getValue(), HTTP.UTF_8); //se.setContentEncoding( HTTP.DEFAULT_CONTENT_CHARSET); request.setEntity(se); Lgr.v(TAG, "Sending json parameter: " + params.get(0).getValue()); if (se != null) { Lgr.v(TAG, "Entity string: " + se.toString()); if (se.getContentEncoding() != null) { Lgr.v(TAG, "Entity encoding: " + request.getEntity().getContentEncoding().getValue()); } } } else if (params.get(0).getName() == "xml") { se = new StringEntity(params.get(0).getValue(), HTTP.DEFAULT_CONTENT_CHARSET); request.setEntity(se); Lgr.v(TAG, "Sending xml parameter: " + params.get(0).getValue()); } else { request.setEntity(new UrlEncodedFormEntity(params, HTTP.DEFAULT_CONTENT_CHARSET)); Lgr.v(TAG, "Sending UrlEncodedForm parameters "); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } Lgr.v(TAG, "Request " + request.toString()); executeRequest(request, url, listener); break; } case PUT: { HttpPut request = new HttpPut(url); // add headers if (headers != null) { for (NameValuePair h : headers) request.addHeader(h.getName(), h.getValue()); } if (params != null) { try { if (params.get(0).getName() == "json") { se = new StringEntity(params.get(0).getValue(), HTTP.DEFAULT_CONTENT_CHARSET); request.setEntity(se); Lgr.v(TAG, "Sending json parameter: " + params.get(0).getValue()); } else if (params.get(0).getName() == "xml") { se = new StringEntity(params.get(0).getValue(), HTTP.DEFAULT_CONTENT_CHARSET); request.setEntity(se); Lgr.v(TAG, "Sending xml parameter: " + params.get(0).getValue()); } else if (params.get(0).getName() == "string") { se = new StringEntity(params.get(0).getValue(), HTTP.DEFAULT_CONTENT_CHARSET); request.setEntity(se); Lgr.v(TAG, "Sending string parameter: " + params.get(0).getValue()); } else { request.setEntity(new UrlEncodedFormEntity(params, HTTP.DEFAULT_CONTENT_CHARSET)); Lgr.v(TAG, "Sending UrlEncodedForm parameters "); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } Lgr.v(TAG, "Request " + request.toString()); executeRequest(request, url, listener); break; } case PATCH: { HttpPatch request = new HttpPatch(url); // add headers if (headers != null) { for (NameValuePair h : headers) request.addHeader(h.getName(), h.getValue()); } if (params != null) { try { if (params.get(0).getName() == "json") { se = new StringEntity(params.get(0).getValue(), HTTP.DEFAULT_CONTENT_CHARSET); request.setEntity(se); Lgr.v(TAG, "Sending json parameter: " + params.get(0).getValue()); } else if (params.get(0).getName() == "xml") { se = new StringEntity(params.get(0).getValue(), HTTP.DEFAULT_CONTENT_CHARSET); request.setEntity(se); Lgr.v(TAG, "Sending xml parameter: " + params.get(0).getValue()); } else if (params.get(0).getName() == "string") { se = new StringEntity(params.get(0).getValue(), HTTP.DEFAULT_CONTENT_CHARSET); request.setEntity(se); Lgr.v(TAG, "Sending string parameter: " + params.get(0).getValue()); } else { request.setEntity(new UrlEncodedFormEntity(params, HTTP.DEFAULT_CONTENT_CHARSET)); Lgr.v(TAG, "Sending UrlEncodedForm parameters "); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } Lgr.v(TAG, "Request " + request.toString()); executeRequest(request, url, listener); break; } case HEAD: { HttpHead request = new HttpHead(url); // add headers if (headers != null) { for (NameValuePair h : headers) request.addHeader(h.getName(), h.getValue()); } Lgr.v(TAG, "Request " + request.toString()); executeRequest(request, url, listener); break; } case DELETE: { HttpDelete request = new HttpDelete(url); // add headers if (headers != null) { for (NameValuePair h : headers) request.addHeader(h.getName(), h.getValue()); } executeRequest(request, url, listener); break; } } } }.start(); }