當前位置: 首頁>>代碼示例>>Java>>正文


Java AndroidHttpClient類代碼示例

本文整理匯總了Java中android.net.http.AndroidHttpClient的典型用法代碼示例。如果您正苦於以下問題:Java AndroidHttpClient類的具體用法?Java AndroidHttpClient怎麽用?Java AndroidHttpClient使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AndroidHttpClient類屬於android.net.http包,在下文中一共展示了AndroidHttpClient類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: newRequestQueue

import android.net.http.AndroidHttpClient; //導入依賴的package包/類
/**
 * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it.
 *
 * @param context A {@link Context} to use for creating the cache dir.
 * @param stack An {@link HttpStack} to use for the network, or null for default.
 * @return A started {@link RequestQueue} instance.
 */
public static RequestQueue newRequestQueue(Context context, HttpStack stack) {
    File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR);

    String userAgent = "volley/0";
    try {
        String packageName = context.getPackageName();
        PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
        userAgent = packageName + "/" + info.versionCode;
    } catch (NameNotFoundException e) {
    }

    if (stack == null) {
        if (Build.VERSION.SDK_INT >= 9) {
            stack = new HurlStack();
        } else {
            // Prior to Gingerbread, HttpUrlConnection was unreliable.
            // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html
            stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent));
        }
    }

    Network network = new BasicNetwork(stack);

    RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network);
    queue.start();

    return queue;
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:36,代碼來源:Volley.java

示例2: 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();
  }
}
 
開發者ID:Leanplum,項目名稱:Leanplum-Android-SDK,代碼行數:11,代碼來源:SocketIOClient.java

示例3: createHttpClient

import android.net.http.AndroidHttpClient; //導入依賴的package包/類
private static AndroidHttpClient createHttpClient(Context context) {
    String userAgent = MmsConfig.getUserAgent();
    AndroidHttpClient client = AndroidHttpClient.newInstance(userAgent, context);
    HttpParams params = client.getParams();
    HttpProtocolParams.setContentCharset(params, "UTF-8");

    // set the socket timeout
    int soTimeout = MmsConfig.getHttpSocketTimeout();

    if (DEBUG) {
        Log.d(TAG, "[HttpUtils] createHttpClient w/ socket timeout " + soTimeout + " ms, "
                + ", UA=" + userAgent);
    }
    HttpConnectionParams.setSoTimeout(params, soTimeout);
    return client;
}
 
開發者ID:ivanovpv,項目名稱:darksms,代碼行數:17,代碼來源:HttpUtils.java

示例4: executeDownload

import android.net.http.AndroidHttpClient; //導入依賴的package包/類
/**
    * Fully execute a single download request - setup and send the request,
    * handle the response, and transfer the data to the destination file.
    */
   private void executeDownload(State state, AndroidHttpClient client,
    HttpGet request) throws StopRequest, RetryDownload {
InnerState innerState = new InnerState();
byte data[] = new byte[Constants.BUFFER_SIZE];

setupDestinationFile(state, innerState);
addRequestHeaders(innerState, request);

// check just before sending the request to avoid using an invalid
// connection at all
checkConnectivity(state);

HttpResponse response = sendRequest(state, client, request);
handleExceptionalStatus(state, innerState, response);

if (Constants.LOGV) {
    Log.v(Constants.TAG, "received response for " + mInfo.mUri);
}

processResponseHeaders(state, innerState, response);
InputStream entityStream = openResponseEntity(state, response);
transferData(state, innerState, data, entityStream);
   }
 
開發者ID:hubcarl,項目名稱:mobile-manager-tool,代碼行數:28,代碼來源:DownloadThread.java

示例5: getDefaultStack

import android.net.http.AndroidHttpClient; //導入依賴的package包/類
private static HttpStack getDefaultStack(Context context){
    String userAgent = "volley/0";
    try {
        String packageName = context.getPackageName();

        PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
        userAgent = packageName + "/" + info.versionCode;
    } catch (NameNotFoundException e) {
    }
    
    if (Build.VERSION.SDK_INT >= 9) {
       return new HurlStack();
    } else {
        // Prior to Gingerbread, HttpUrlConnection was unreliable.
        // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html
        return new HttpClientStack(AndroidHttpClient.newInstance(userAgent));
    }    	
}
 
開發者ID:active-citizen,項目名稱:android.java,代碼行數:19,代碼來源:Volley.java

示例6: 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";
}
 
開發者ID:DerGary,項目名稱:FHWS-MobileApplikationen,代碼行數:21,代碼來源:MainActivity.java

示例7: 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";
}
 
開發者ID:DerGary,項目名稱:FHWS-MobileApplikationen,代碼行數:26,代碼來源:DemoAppWidget.java

示例8: doInBackground

import android.net.http.AndroidHttpClient; //導入依賴的package包/類
@Override
protected VastVideoConfiguration doInBackground(@Nullable String... strings) {
    AndroidHttpClient httpClient = null;
    try {
        httpClient = HttpClient.getHttpClient();
        if (strings != null && strings.length > 0) {
            String vastXml = strings[0];
            if (vastXml == null) {
                return null;
            }
            return evaluateVastXmlManager(vastXml, httpClient, new ArrayList<VastTracker>());
        }
    } catch (Exception e) {
        MoPubLog.d("Failed to parse VAST XML", e);
    } finally {
        if (httpClient != null) {
            httpClient.close();
        }
    }

    return null;
}
 
開發者ID:JSafaiyeh,項目名稱:Fabric-Example-App-Android,代碼行數:23,代碼來源:VastXmlManagerAggregator.java

示例9: evaluateWrapperRedirect

import android.net.http.AndroidHttpClient; //導入依賴的package包/類
/**
 * Retrieves the Wrapper's redirect uri and follows it to return the next VAST xml String.
 *
 * @param vastWrapperXmlManager used to get the redirect uri
 * @param androidHttpClient     the http client
 * @param wrapperErrorTrackers  Error trackers to hit if something goes wrong
 * @return the next VAST xml String or {@code null} if it could not be resolved
 */
@Nullable
private String evaluateWrapperRedirect(@NonNull VastWrapperXmlManager vastWrapperXmlManager,
        @NonNull AndroidHttpClient androidHttpClient,
        @NonNull List<VastTracker> wrapperErrorTrackers) {
    String vastAdTagUri = vastWrapperXmlManager.getVastAdTagURI();
    if (vastAdTagUri == null) {
        return null;
    }

    String vastRedirectXml = null;
    try {
        vastRedirectXml = followVastRedirect(androidHttpClient, vastAdTagUri);
    } catch (Exception e) {
        MoPubLog.d("Failed to follow VAST redirect", e);
        if (!wrapperErrorTrackers.isEmpty()) {
            makeVastTrackingHttpRequest(wrapperErrorTrackers, VastErrorCode.WRAPPER_TIMEOUT,
                            null, null, mContext);
        }
    }

    return vastRedirectXml;
}
 
開發者ID:JSafaiyeh,項目名稱:Fabric-Example-App-Android,代碼行數:31,代碼來源:VastXmlManagerAggregator.java

示例10: 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;
}
 
開發者ID:JSafaiyeh,項目名稱:Fabric-Example-App-Android,代碼行數:17,代碼來源:VastXmlManagerAggregator.java

示例11: 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();
        }
    }
}
 
開發者ID:JSafaiyeh,項目名稱:Fabric-Example-App-Android,代碼行數:25,代碼來源:DownloadTask.java

示例12: 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);
}
 
開發者ID:BlochsTech,項目名稱:BitcoinCardTerminal,代碼行數:24,代碼來源:WebUtil.java

示例13: 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);
}
 
開發者ID:BlochsTech,項目名稱:BitcoinCardTerminal,代碼行數:24,代碼來源:WebUtil.java

示例14: AddServersFromOnlineSource

import android.net.http.AndroidHttpClient; //導入依賴的package包/類
private void AddServersFromOnlineSource(){
	//Get updated servers list from BlochsTech.com/StratumServers.json
	try{
		AndroidHttpClient client = AndroidHttpClient.newInstance("BOBC-0 Terminal/0.0/Android");
		SimpleWebResponse resp = WebUtil.SimpleHttpGet(client, "http://blochstech.com/content/StratumServers.txt", "text/plain", "StratumServerManager_GetBlochsTechServerList");
		if(resp.IsConnected && resp.Response != null){
			JSONObject json = new JSONObject(resp.Response);
			JSONArray jsonServers = json.getJSONArray("Servers");
			String url;
			for(int i = 0; i < jsonServers.length(); i++){
				url = jsonServers.getString(i);
				if(!ContainsServer(url))
					servers.add(new StratumServer(url));
			}
		}
	}catch(Exception ex){
		if(Tags.DEBUG)
			Log.e(Tags.APP_TAG, "Failed to get StratumServers from online source. Ex: " + ex.toString());
	}
}
 
開發者ID:BlochsTech,項目名稱:BitcoinCardTerminal,代碼行數:21,代碼來源:StratumServerManager.java

示例15: newRequestQueue

import android.net.http.AndroidHttpClient; //導入依賴的package包/類
private static RequestQueue newRequestQueue(Context context) {

        // On HC+ use HurlStack which is based on HttpURLConnection. Otherwise fall back on
        // AndroidHttpClient (based on Apache DefaultHttpClient) which should no longer be used
        // on newer platform versions where HttpURLConnection is simply better.
        Network network = new BasicNetwork(
                UIUtils.hasHoneycomb() ?
                        new HurlStack() :
                        new HttpClientStack(AndroidHttpClient.newInstance(
                                NetUtils.getUserAgent(context))));

        Cache cache = new DiskBasedCache(getDiskCacheDir(context, CACHE_DIR));
        RequestQueue queue = new RequestQueue(cache, network);
        queue.start();
        return queue;
    }
 
開發者ID:BitCypher2014,項目名稱:Wardrobe_app,代碼行數:17,代碼來源:ImageLoader.java


注:本文中的android.net.http.AndroidHttpClient類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。