本文整理汇总了Java中android.net.http.AndroidHttpClient.execute方法的典型用法代码示例。如果您正苦于以下问题:Java AndroidHttpClient.execute方法的具体用法?Java AndroidHttpClient.execute怎么用?Java AndroidHttpClient.execute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.net.http.AndroidHttpClient
的用法示例。
在下文中一共展示了AndroidHttpClient.execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: downloadUriAsString
import android.net.http.AndroidHttpClient; //导入方法依赖的package包/类
private static String downloadUriAsString(final HttpUriRequest req)
throws IOException {
AndroidHttpClient client = AndroidHttpClient.newInstance(userAgentString());
try {
HttpResponse res = client.execute(req);
return readToEnd(res.getEntity().getContent());
} finally {
client.close();
}
}
示例2: doInBackground
import android.net.http.AndroidHttpClient; //导入方法依赖的package包/类
@Override
protected String doInBackground(String... url) {
AndroidHttpClient httpClient = AndroidHttpClient.newInstance("test");
HttpGet get = new HttpGet("http://backend.applab.fhws.de:8080/fhws/simple");
try
{
HttpResponse response = httpClient.execute(get);
InputStream is = response.getEntity().getContent();
return IOUtils.toString(is);
}
catch( Exception e )
{
e.printStackTrace();
}
return "Error";
}
示例3: doInBackground
import android.net.http.AndroidHttpClient; //导入方法依赖的package包/类
@Override
protected String doInBackground( Void... params )
{
AndroidHttpClient httpClient = AndroidHttpClient.newInstance( "" );
HttpGet get = new HttpGet( URL );
try
{
HttpResponse response = httpClient.execute( get );
HttpEntity entity = response.getEntity( );
InputStreamReader reader = new InputStreamReader( entity.getContent( ) );
BufferedReader bufReader = new BufferedReader( reader );
String status = bufReader.readLine( );
entity.consumeContent( );
return status;
}
catch ( Exception e )
{
Log.e( "WIDGET", e.getMessage( ) );
}
return "No status received";
}
示例4: followVastRedirect
import android.net.http.AndroidHttpClient; //导入方法依赖的package包/类
@Nullable
private String followVastRedirect(@NonNull final AndroidHttpClient httpClient,
@NonNull final String redirectUrl) throws Exception {
Preconditions.checkNotNull(httpClient);
Preconditions.checkNotNull(redirectUrl);
if (mTimesFollowedVastRedirect < MAX_TIMES_TO_FOLLOW_VAST_REDIRECT) {
mTimesFollowedVastRedirect++;
final HttpGet httpget = HttpClient.initializeHttpGet(redirectUrl);
final HttpResponse response = httpClient.execute(httpget);
final HttpEntity entity = response.getEntity();
return (entity != null) ? Strings.fromStream(entity.getContent()) : null;
}
return null;
}
示例5: doInBackground
import android.net.http.AndroidHttpClient; //导入方法依赖的package包/类
@Override
protected DownloadResponse doInBackground(final HttpUriRequest... httpUriRequests) {
if (httpUriRequests == null || httpUriRequests.length == 0 || httpUriRequests[0] == null) {
MoPubLog.d("Download task tried to execute null or empty url");
return null;
}
final HttpUriRequest httpUriRequest = httpUriRequests[0];
mUrl = httpUriRequest.getURI().toString();
AndroidHttpClient httpClient = null;
try {
httpClient = HttpClient.getHttpClient();
final HttpResponse httpResponse = httpClient.execute(httpUriRequest);
return new DownloadResponse(httpResponse);
} catch (Exception e) {
MoPubLog.d("Download task threw an internal exception", e);
return null;
} finally {
if (httpClient != null) {
httpClient.close();
}
}
}
示例6: SimpleHttpGet
import android.net.http.AndroidHttpClient; //导入方法依赖的package包/类
public static SimpleWebResponse SimpleHttpGet(AndroidHttpClient client, String url, String contentType, String callerDebugName) throws IOException{
String netResult = "", line;
HttpGet getRequest = new HttpGet(url);
getRequest.addHeader("accept", contentType);
HttpResponse response = client.execute(getRequest);
if (response.getStatusLine().getStatusCode() != 200) {
HttpResponseLog(response, callerDebugName);
return new SimpleWebResponse(null, false);
}else{
BufferedReader br = new BufferedReader(
new InputStreamReader((response.getEntity().getContent())));
while ((line = br.readLine()) != null) {
netResult = netResult + line;
}
}
return new SimpleWebResponse(netResult, true);
}
示例7: SimpleHttpPost
import android.net.http.AndroidHttpClient; //导入方法依赖的package包/类
public static SimpleWebResponse SimpleHttpPost(AndroidHttpClient client, String url, String body, String contentType, String callerDebugName) throws IOException {
String netResult = "", line;
HttpPost postRequest = new HttpPost(url);
postRequest.addHeader("accept", contentType);
postRequest.setEntity(new StringEntity(body, "UTF8"));
HttpResponse response = client.execute(postRequest);
if (response.getStatusLine().getStatusCode() != 200) {
HttpResponseLog(response, callerDebugName);
return new SimpleWebResponse(null, false);
}else{
BufferedReader br = new BufferedReader(
new InputStreamReader((response.getEntity().getContent())));
while ((line = br.readLine()) != null) {
netResult = netResult + line;
}
}
return new SimpleWebResponse(netResult, true);
}
示例8: doInBackground
import android.net.http.AndroidHttpClient; //导入方法依赖的package包/类
@Override
protected HttpResponse doInBackground(String... params) {
String link = params[0];
String payload = params[1];
AndroidHttpClient client = AndroidHttpClient.newInstance("Android");
HttpPost request = new HttpPost(link);
HttpResponse response = null;
request.setHeader( "Content-Type", "application/json" );
try {
StringEntity se = new StringEntity(payload);
se.setContentEncoding("UTF-8");
se.setContentType("application/json");
request.setEntity(se);
response = client.execute(request);
} catch (IOException e) {
log(e.getMessage());
e.printStackTrace();
} finally {
client.close();
}
return response;
}
示例9: HttpGetAnswer
import android.net.http.AndroidHttpClient; //导入方法依赖的package包/类
public static String HttpGetAnswer(String url) throws ClientProtocolException, IOException, JSONException, HttpException{
AndroidHttpClient client = AndroidHttpClient.newInstance(null);
client.getParams().setParameter(HttpConnectionParams.CONNECTION_TIMEOUT, 7500);
client.getParams().setParameter(HttpConnectionParams.SO_TIMEOUT, 7500);
HttpGet httpGet = new HttpGet(url);
HttpResponse response = client.execute(httpGet);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) {
String resp = EntityUtils.toString(response.getEntity());
client.close();
return resp;
} else {
try {
client.close();
}catch (Exception ex){}
throw new HttpException("STATUSCODE!=200");
}
}
示例10: HttpPostAnswer
import android.net.http.AndroidHttpClient; //导入方法依赖的package包/类
public static String HttpPostAnswer(String url, JSONObject jobj) throws ClientProtocolException, IOException, JSONException, HttpException{
AndroidHttpClient client = AndroidHttpClient.newInstance(null);
client.getParams().setParameter(HttpConnectionParams.CONNECTION_TIMEOUT, 7500);
client.getParams().setParameter(HttpConnectionParams.SO_TIMEOUT, 7500);
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new StringEntity(jobj.toString()));
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/json");
HttpResponse response = client.execute(httpPost);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) {
String resp = EntityUtils.toString(response.getEntity());
client.close();
return resp;
} else {
try {
client.close();
}catch (Exception ex){}
throw new HttpException("STATUSCODE!=200");
}
}
示例11: HttpPostAnswerJsonObject
import android.net.http.AndroidHttpClient; //导入方法依赖的package包/类
public static JSONObject HttpPostAnswerJsonObject(String url, JSONObject obj) throws ClientProtocolException, IOException, JSONException, HttpException{
AndroidHttpClient client = AndroidHttpClient.newInstance(null);
client.getParams().setParameter(HttpConnectionParams.CONNECTION_TIMEOUT, 60000);
client.getParams().setParameter(HttpConnectionParams.SO_TIMEOUT, 60000);
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new StringEntity(obj.toString()));
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/json");
HttpResponse response = client.execute(httpPost);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) {
String raw = EntityUtils.toString(response.getEntity());
JSONObject jobj = new JSONObject(raw);
client.close();
return jobj;
} else {
try {
client.close();
}catch (Exception ex){}
throw new HttpException("STATUSCODE!=200");
}
}
示例12: HttpPostAnswerJsonArray
import android.net.http.AndroidHttpClient; //导入方法依赖的package包/类
public static JSONArray HttpPostAnswerJsonArray(String url, JSONObject obj) throws ClientProtocolException, IOException, JSONException, HttpException{
AndroidHttpClient client = AndroidHttpClient.newInstance(null);
client.getParams().setParameter(HttpConnectionParams.CONNECTION_TIMEOUT, 10000);
client.getParams().setParameter(HttpConnectionParams.SO_TIMEOUT, 10000);
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new StringEntity(obj.toString()));
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/json");
HttpResponse response = client.execute(httpPost);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) {
String raw = EntityUtils.toString(response.getEntity());
JSONArray jarr = new JSONArray(raw);
client.close();
return jarr;
} else {
try {
client.close();
}catch (Exception ex){}
throw new HttpException("STATUSCODE!=200");
}
}
示例13: checkUrl
import android.net.http.AndroidHttpClient; //导入方法依赖的package包/类
/**
* Check if a URL is valid and points to a resource on the remote web
* server. Used to check if certain image sizes are available.
*
* @param url
* @return
*/
public static boolean checkUrl(String url) {
Log.d(LOG_TAG, "checkUrl: " + url);
final AndroidHttpClient client = AndroidHttpClient.newInstance("Android");
final HttpGet request = new HttpGet(url);
try {
HttpResponse response = client.execute(request);
final int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == HttpStatus.SC_OK) {
return true;
}
} catch (Exception e) {
request.abort();
} finally {
if (client != null) {
client.close();
}
}
return false;
}
示例14: doRequest
import android.net.http.AndroidHttpClient; //导入方法依赖的package包/类
private static BackendConnectionResult doRequest(HttpUriRequest request) {
RequestAnalytics analytics = new RequestAnalytics(request);
AndroidHttpClient httpClient = AndroidHttpClient.newInstance(userAgent);
BackendConnectionResult result;
try {
HttpResponse response = httpClient.execute(request);
InputStream inputStream = response.getEntity().getContent();
StatusLine statusLine = response.getStatusLine();
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, Charsets.UTF_8);
String contentString = CharStreams.toString(inputStreamReader);
inputStreamReader.close();
httpClient.close();
result = new BackendConnectionResult(statusLine, contentString);
} catch (IOException e) {
result = new BackendConnectionResult(e);
}
analytics.done(result);
return result;
}
示例15: doInBackground
import android.net.http.AndroidHttpClient; //导入方法依赖的package包/类
@Override
protected Integer doInBackground(String... url) {
AndroidHttpClient httpClient = AndroidHttpClient.newInstance("test");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("size", Integer.toString(100)));
nameValuePairs.add(new BasicNameValuePair("pause", Integer.toString(10)));
HttpGet get = new HttpGet("http://" + HOST + ":8080/fhws/progress?" + URLEncodedUtils.format(nameValuePairs, "UTF-8"));
int size = 0;
try
{
HttpResponse response = httpClient.execute(get);
size = Integer.parseInt(response.getFirstHeader(HTTP.CONTENT_LEN).getValue());
InputStream is = response.getEntity().getContent();
for( int i=0; i<size; i++ )
{
is.read();
int progress = (int)((i/(float)size)*100);
publishProgress(progress);
}
}
catch( Exception e )
{
e.printStackTrace();
}
return size;
}