本文整理汇总了Java中cz.msebera.android.httpclient.client.methods.HttpGet类的典型用法代码示例。如果您正苦于以下问题:Java HttpGet类的具体用法?Java HttpGet怎么用?Java HttpGet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpGet类属于cz.msebera.android.httpclient.client.methods包,在下文中一共展示了HttpGet类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import cz.msebera.android.httpclient.client.methods.HttpGet; //导入依赖的package包/类
public static Hostplace get(String ip) throws Exception {
HttpGet httppost = new HttpGet(Geocode.url + "/" + ip);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httppost);
// StatusLine stat = response.getStatusLine();
int status = response.getStatusLine().getStatusCode();
if (status == 200) {
HttpEntity entity = response.getEntity();
String data = EntityUtils.toString(entity);
JSONObject json = new JSONObject(data);
if (json.getString("status").equals("fail"))
throw new Exception();
Hostplace hostplace = Hostplace.getJson(json);
return hostplace;
}
throw new Exception();
}
示例2: getBlock
import cz.msebera.android.httpclient.client.methods.HttpGet; //导入依赖的package包/类
public static Block getBlock(String blockhash) throws Exception {
HttpGet httppost = new HttpGet(Insight.url + "/block/" + blockhash);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httppost);
// StatusLine stat = response.getStatusLine();
int status = response.getStatusLine().getStatusCode();
if (status == 200) {
HttpEntity entity = response.getEntity();
String data = EntityUtils.toString(entity);
JSONObject json = new JSONObject(data);
Block block = Block.getJson(json);
return block;
}
throw new Exception();
}
示例3: getBlockHash
import cz.msebera.android.httpclient.client.methods.HttpGet; //导入依赖的package包/类
public static String getBlockHash(String height) throws Exception {
HttpGet httppost = new HttpGet(Insight.url + "/block-index/" + height);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httppost);
// StatusLine stat = response.getStatusLine();
int status = response.getStatusLine().getStatusCode();
if (status == 200) {
HttpEntity entity = response.getEntity();
String data = EntityUtils.toString(entity);
JSONObject json = new JSONObject(data);
String hash = json.getString("blockHash");
return hash;
}
throw new Exception();
}
示例4: getTx
import cz.msebera.android.httpclient.client.methods.HttpGet; //导入依赖的package包/类
public static Tx getTx(String hash) throws Exception {
HttpGet httppost = new HttpGet(Insight.url + "/tx/" + hash);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httppost);
// StatusLine stat = response.getStatusLine();
int status = response.getStatusLine().getStatusCode();
if (status == 200) {
HttpEntity entity = response.getEntity();
String data = EntityUtils.toString(entity);
JSONObject json = new JSONObject(data);
Tx tx = Tx.getJson(json);
return tx;
}
throw new Exception();
}
示例5: performHttpGet
import cz.msebera.android.httpclient.client.methods.HttpGet; //导入依赖的package包/类
public void performHttpGet(String uri, HttpResponseCallback callback) {
try {
HttpGet get = new HttpGet(new URI(uri));
CloseableHttpResponse response = client.execute(get);
int status = response.getStatusLine().getStatusCode();
try {
HttpEntity entity = response.getEntity();
String json = EntityUtils.toString(entity);
EntityUtils.consume(entity);
callback.onHttpResponse(status, json);
} finally {
response.close();
}
} catch (IOException | URISyntaxException e) {
callback.onException(e);
}
}
示例6: performBinaryHttpGet
import cz.msebera.android.httpclient.client.methods.HttpGet; //导入依赖的package包/类
public void performBinaryHttpGet(String uri, BinaryHttpResponseCallback callback) {
try {
HttpGet get = new HttpGet(new URI(uri));
CloseableHttpResponse response = client.execute(get);
int status = response.getStatusLine().getStatusCode();
try {
HttpEntity entity = response.getEntity();
callback.onHttpResponse(status, entity.getContent());
EntityUtils.consume(entity);
} finally {
response.close();
}
} catch (IOException | URISyntaxException e) {
callback.onException(e);
}
}
示例7: doesWikiPageExist
import cz.msebera.android.httpclient.client.methods.HttpGet; //导入依赖的package包/类
/**
* Returns whether or not a given wiki page or file exists.
*
* @param httpclient an active HTTP session
* @param pagename the name of the wiki page
* @return true if the page exists, false if not
* @throws WikiException problem with the wiki, translate the ID
* @throws Exception anything else happened, use getMessage
*/
public static boolean doesWikiPageExist(@NonNull CloseableHttpClient httpclient,
@NonNull String pagename) throws Exception {
// It's GET time! This is basically the same as the content request, but
// we really don't need ANY data other than whether or not the page
// exists, so we won't call for anything.
HttpGet httpget = new HttpGet(WIKI_API_URL + "?action=query&format=xml&titles="
+ URLEncoder.encode(pagename, "UTF-8"));
WikiResponse response = getWikiResponse(httpclient, httpget);
Element pageElem;
try {
pageElem = DOMUtil.getFirstElement(response.rootElem, "page");
} catch(Exception e) {
throw new WikiException(R.string.wiki_error_xml);
}
// "invalid" or "missing" both resolve to the same answer: No. Anything
// else means yes.
return !(pageElem.hasAttribute("invalid") || pageElem.hasAttribute("missing"));
}
示例8: getWikiVersion
import cz.msebera.android.httpclient.client.methods.HttpGet; //导入依赖的package包/类
/**
* Gets the version of the wiki. This may be needed if there is an
* impending upgrade that breaks certain API calls and we want to make sure
* we're calling the right one depending on if the Geohashing wiki has
* upgraded yet. In times of stable APIs, this probably won't be used.
*
* @param httpclient an active HTTP session
* @return a {@link WikiVersionData} containing all the version data you'll need
* @throws WikiException problem with the wiki, translate the ID
* @throws Exception anything else happened, use getMessage
*/
@NonNull
@SuppressWarnings("unused")
public static WikiVersionData getWikiVersion(@NonNull CloseableHttpClient httpclient) throws Exception {
// SiteInfo call!
HttpGet httpget = new HttpGet(WIKI_API_URL + "?action=query&format=xml&meta=siteinfo&siprop=general");
WikiResponse response = getWikiResponse(httpclient, httpget);
Element generalElem;
try {
generalElem = DOMUtil.getFirstElement(response.rootElem, "general");
} catch(Exception e) {
throw new WikiException(R.string.wiki_error_xml);
}
// If the generator attribute isn't there, there's a problem.
if(!generalElem.hasAttribute("generator")) {
throw new WikiException(R.string.wiki_error_xml);
}
// Finally, we've got us a WikiVersionData!
return new WikiVersionData(generalElem.getAttribute("generator"));
}
示例9: get
import cz.msebera.android.httpclient.client.methods.HttpGet; //导入依赖的package包/类
public static CloseableHttpResponse get(CloseableHttpClient httpClient, String url, Map<String, String> params, Map<String, String> headers) throws IOException {
System.out.println("url:"+url);
System.out.println("params:"+MapUtil.getEncodedUrl(params));
System.out.println("headers:"+MapUtil.getEncodedUrl(headers));
String urlParamString = MapUtil.getEncodedUrl(params);
if(urlParamString.length()>0){
if(url.contains("?")){
url = String.format("%s&%s",url,urlParamString);
}else{
url = String.format("%s?%s",url,urlParamString);
}
}
HttpGet httpGet = new HttpGet(url);
for(Map.Entry<String,String> entry:headers.entrySet()){
httpGet.setHeader(entry.getKey(),entry.getValue());
}
return httpClient.execute(httpGet);
}
示例10: getHtmlConsolePage
import cz.msebera.android.httpclient.client.methods.HttpGet; //导入依赖的package包/类
private static String getHtmlConsolePage(String dev_acc, CookieStore cookieStore) throws IOException, NetworkException {
HttpGet get = new HttpGet(Utils.DEVELOPER_CONSOLE_URL + "?dev_acc=" + dev_acc);
HttpClient client = HttpClientBuilder.create().setDefaultCookieStore(cookieStore).build();
HttpResponse resp = client.execute(get);
StatusLine sl = resp.getStatusLine();
if (sl.getStatusCode() != 200) throw new NetworkException(sl);
return EntityUtils.toString(resp.getEntity(), Charset.forName("UTF-8"));
}
示例11: getResponseFromGetUrl
import cz.msebera.android.httpclient.client.methods.HttpGet; //导入依赖的package包/类
public static String getResponseFromGetUrl(String url,
String params) throws Exception {
Log.d("Chen", "url--" + url);
if (null != params && !"".equals(params)) {
url = url + "?";
String[] paramarray = params.split(",");
for (int index = 0; null != paramarray && index < paramarray.length; index++) {
if (index == 0) {
url = url + paramarray[index];
} else {
url = url + "&" + paramarray[index];
}
}
}
HttpGet httpRequest = new HttpGet(url);
// httpRequest.addHeader("Cookie", logininfo);
HttpParams httpParameters = new BasicHttpParams();
// Set the timeout in milliseconds until a connection is established.
int timeoutConnection = 30000;
HttpConnectionParams.setConnectionTimeout(httpParameters,
timeoutConnection);
// Set the default socket timeout (SO_TIMEOUT)
// in milliseconds which is the timeout for waiting for data.
int timeoutSocket = 30000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
DefaultHttpClient httpclient = new DefaultHttpClient(httpParameters);
// DefaultHttpClient httpclient = new DefaultHttpClient();
StringBuffer sb = new StringBuffer();
try {
HttpResponse httpResponse = httpclient.execute(httpRequest);
String inputLine = "";
// Log.d("Chen","httpResponse.getStatusLine().getStatusCode()"+httpResponse.getStatusLine().getStatusCode());
if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
InputStreamReader is = new InputStreamReader(httpResponse
.getEntity().getContent());
BufferedReader in = new BufferedReader(is);
while ((inputLine = in.readLine()) != null) {
sb.append(inputLine);
}
in.close();
} else if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_MODIFIED) {
return "";
}
} catch (Exception e) {
e.printStackTrace();
return "";
} finally {
httpclient.getConnectionManager().shutdown();
}
return sb.toString();
}