use of org.apache.http.client.methods.HttpDelete in project Fling by entertailion.
the class RampClient method closeCurrentApp.
public void closeCurrentApp() {
if (dialServer != null) {
try {
DefaultHttpClient defaultHttpClient = HttpRequestHelper.createHttpClient();
CustomRedirectHandler handler = new CustomRedirectHandler();
defaultHttpClient.setRedirectHandler(handler);
BasicHttpContext localContext = new BasicHttpContext();
// check if any app is running
HttpGet httpGet = new HttpGet(dialServer.getAppsUrl());
httpGet.setHeader(HEADER_CONNECTION, HEADER_CONNECTION_VALUE);
httpGet.setHeader(HEADER_USER_AGENT, HEADER_USER_AGENT_VALUE);
httpGet.setHeader(HEADER_ACCEPT, HEADER_ACCEPT_VALUE);
httpGet.setHeader(HEADER_DNT, HEADER_DNT_VALUE);
httpGet.setHeader(HEADER_ACCEPT_ENCODING, HEADER_ACCEPT_ENCODING_VALUE);
httpGet.setHeader(HEADER_ACCEPT_LANGUAGE, HEADER_ACCEPT_LANGUAGE_VALUE);
HttpResponse httpResponse = defaultHttpClient.execute(httpGet);
if (httpResponse != null) {
int responseCode = httpResponse.getStatusLine().getStatusCode();
Log.d(LOG_TAG, "get response code=" + httpResponse.getStatusLine().getStatusCode());
if (responseCode == 204) {
// nothing is running
} else if (responseCode == 200) {
// app is running
// Need to get real URL after a redirect
// http://stackoverflow.com/a/10286025/594751
String lastUrl = dialServer.getAppsUrl();
if (handler.lastRedirectedUri != null) {
lastUrl = handler.lastRedirectedUri.toString();
Log.d(LOG_TAG, "lastUrl=" + lastUrl);
}
String response = EntityUtils.toString(httpResponse.getEntity());
Log.d(LOG_TAG, "get response=" + response);
parseXml(new StringReader(response));
Header[] headers = httpResponse.getAllHeaders();
for (int i = 0; i < headers.length; i++) {
Log.d(LOG_TAG, headers[i].getName() + "=" + headers[i].getValue());
}
// stop the app instance
HttpDelete httpDelete = new HttpDelete(lastUrl);
httpResponse = defaultHttpClient.execute(httpDelete);
if (httpResponse != null) {
Log.d(LOG_TAG, "delete response code=" + httpResponse.getStatusLine().getStatusCode());
response = EntityUtils.toString(httpResponse.getEntity());
Log.d(LOG_TAG, "delete response=" + response);
} else {
Log.d(LOG_TAG, "no delete response");
}
}
} else {
Log.i(LOG_TAG, "no get response");
return;
}
} catch (Exception e) {
Log.e(LOG_TAG, "closeCurrentApp", e);
}
}
}
use of org.apache.http.client.methods.HttpDelete in project android-volley by mcxiaoke.
the class HttpClientStackTest method createDeleteRequest.
@Test
public void createDeleteRequest() throws Exception {
TestRequest.Delete request = new TestRequest.Delete();
assertEquals(request.getMethod(), Method.DELETE);
HttpUriRequest httpRequest = HttpClientStack.createHttpRequest(request, null);
assertTrue(httpRequest instanceof HttpDelete);
}
use of org.apache.http.client.methods.HttpDelete in project OpenAttestation by OpenAttestation.
the class ApacheHttpClient method delete.
public ApiResponse delete(String requestURL) throws IOException, SignatureException {
log.debug("DELETE url: {}", requestURL);
HttpDelete request = new HttpDelete(requestURL);
// send the request and print the response
HttpResponse httpResponse = httpClient.execute(request);
ApiResponse apiResponse = readResponse(httpResponse);
request.releaseConnection();
return apiResponse;
}
use of org.apache.http.client.methods.HttpDelete in project FastDev4Android by jiangqqlmj.
the class HttpClientStackTest method createDeleteRequest.
@Test
public void createDeleteRequest() throws Exception {
TestRequest.Delete request = new TestRequest.Delete();
assertEquals(request.getMethod(), Method.DELETE);
HttpUriRequest httpRequest = HttpClientStack.createHttpRequest(request, null);
assertTrue(httpRequest instanceof HttpDelete);
}
use of org.apache.http.client.methods.HttpDelete in project nanohttpd by NanoHttpd.
the class TestNanolets method doSomeBasicMethodTest.
@Test
public void doSomeBasicMethodTest() throws Exception {
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpGet httpget = new HttpGet("http://localhost:9090/user/blabla");
CloseableHttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
String string = new String(readContents(entity), "UTF-8");
Assert.assertEquals("<html><body>User handler. Method: GET<br><h1>Uri parameters:</h1><div> Param: id Value: blabla</div><h1>Query parameters:</h1></body></html>", string);
response.close();
HttpPost httppost = new HttpPost("http://localhost:9090/user/blabla");
response = httpclient.execute(httppost);
entity = response.getEntity();
string = new String(readContents(entity), "UTF-8");
Assert.assertEquals("<html><body>User handler. Method: POST<br><h1>Uri parameters:</h1><div> Param: id Value: blabla</div><h1>Query parameters:</h1></body></html>", string);
response.close();
HttpPut httpgput = new HttpPut("http://localhost:9090/user/blabla");
response = httpclient.execute(httpgput);
entity = response.getEntity();
string = new String(readContents(entity), "UTF-8");
Assert.assertEquals("<html><body>User handler. Method: PUT<br><h1>Uri parameters:</h1><div> Param: id Value: blabla</div><h1>Query parameters:</h1></body></html>", string);
response.close();
HttpDelete httpdelete = new HttpDelete("http://localhost:9090/user/blabla");
response = httpclient.execute(httpdelete);
entity = response.getEntity();
string = new String(readContents(entity), "UTF-8");
Assert.assertEquals("<html><body>User handler. Method: DELETE<br><h1>Uri parameters:</h1><div> Param: id Value: blabla</div><h1>Query parameters:</h1></body></html>", string);
response.close();
}
Aggregations