use of org.apache.http.client.methods.HttpGet in project qi4j-sdk by Qi4j.
the class MutualSecureJettyServiceTest method testWithoutClientCertificate.
@Test
public void testWithoutClientCertificate() throws IOException {
// As we set wantClientAuth we can request without a client certificate ...
String output = trustHttpClient.execute(new HttpGet("https://127.0.0.1:8441/hello"), stringResponseHandler);
assertEquals("Hello World", output);
}
use of org.apache.http.client.methods.HttpGet in project Anki-Android by Ramblurr.
the class HttpFetcher method fetchThroughHttp.
public static String fetchThroughHttp(String address, String encoding) {
try {
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpGet httpGet = new HttpGet(address);
HttpResponse response = httpClient.execute(httpGet, localContext);
if (!response.getStatusLine().toString().contains("OK")) {
return "FAILED";
}
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), Charset.forName(encoding)));
StringBuilder stringBuilder = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
stringBuilder.append(line);
}
return stringBuilder.toString();
} catch (Exception e) {
return "FAILED with exception: " + e.getMessage();
}
}
use of org.apache.http.client.methods.HttpGet in project Notes by MiCode.
the class GTaskClient method getTaskLists.
public JSONArray getTaskLists() throws NetworkFailureException {
if (!mLoggedin) {
Log.e(TAG, "please login first");
throw new ActionFailureException("not logged in");
}
try {
HttpGet httpGet = new HttpGet(mGetUrl);
HttpResponse response = null;
response = mHttpClient.execute(httpGet);
// get the task list
String resString = getResponseContent(response.getEntity());
String jsBegin = "_setup(";
String jsEnd = ")}</script>";
int begin = resString.indexOf(jsBegin);
int end = resString.lastIndexOf(jsEnd);
String jsString = null;
if (begin != -1 && end != -1 && begin < end) {
jsString = resString.substring(begin + jsBegin.length(), end);
}
JSONObject js = new JSONObject(jsString);
return js.getJSONObject("t").getJSONArray(GTaskStringUtils.GTASK_JSON_LISTS);
} catch (ClientProtocolException e) {
Log.e(TAG, e.toString());
e.printStackTrace();
throw new NetworkFailureException("gettasklists: httpget failed");
} catch (IOException e) {
Log.e(TAG, e.toString());
e.printStackTrace();
throw new NetworkFailureException("gettasklists: httpget failed");
} catch (JSONException e) {
Log.e(TAG, e.toString());
e.printStackTrace();
throw new ActionFailureException("get task lists: handing jasonobject failed");
}
}
use of org.apache.http.client.methods.HttpGet in project 9GAG by Mixiaoxiao.
the class MxxHttpUtil method doHttpGet.
public static String doHttpGet(String url, HashMap<String, String> map) {
HttpClient client = new DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(client.getParams(), TIMEOUT);
HttpConnectionParams.setSoTimeout(client.getParams(), TIMEOUT);
ConnManagerParams.setTimeout(client.getParams(), TIMEOUT);
String result = "ERROR";
if (null != map) {
int i = 0;
for (Map.Entry<String, String> entry : map.entrySet()) {
if (i == 0) {
url = url + "?" + entry.getKey() + "=" + entry.getValue();
} else {
url = url + "&" + entry.getKey() + "=" + entry.getValue();
}
i++;
}
}
HttpGet get = new HttpGet(url);
get.setHeaders(headers);
try {
HttpResponse response = client.execute(get);
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
// setCookie(response);
result = EntityUtils.toString(response.getEntity(), "UTF-8");
} else {
result = EntityUtils.toString(response.getEntity(), "UTF-8") + response.getStatusLine().getStatusCode() + "ERROR";
}
if (result != null) {
if (result.startsWith("")) {
result = result.substring(1);
}
}
} catch (ConnectTimeoutException e) {
result = "TIMEOUTERROR";
} catch (Exception e) {
result = "OTHERERROR";
e.printStackTrace();
}
return result;
}
use of org.apache.http.client.methods.HttpGet in project nanohttpd by NanoHttpd.
the class GetAndPostIntegrationTest method testGetRequestWithParameters.
@Test
public void testGetRequestWithParameters() throws Exception {
this.testServer.response = "testGetRequestWithParameters";
HttpGet httpget = new HttpGet("http://localhost:8192/?age=120&gender=Male");
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseBody = this.httpclient.execute(httpget, responseHandler);
assertEquals("GET:testGetRequestWithParameters-params=2;age=120;gender=Male", responseBody);
}
Aggregations