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


Java OkHttpClient.setProxy方法代碼示例

本文整理匯總了Java中com.squareup.okhttp.OkHttpClient.setProxy方法的典型用法代碼示例。如果您正苦於以下問題:Java OkHttpClient.setProxy方法的具體用法?Java OkHttpClient.setProxy怎麽用?Java OkHttpClient.setProxy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.squareup.okhttp.OkHttpClient的用法示例。


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

示例1: getRealTokenService

import com.squareup.okhttp.OkHttpClient; //導入方法依賴的package包/類
/**
 * Return a instance of tokenService to call it
 * 
 * @param authority
 * @return TokenService return a proxy to call api
 */
private static TokenService getRealTokenService(String authority) {
	// Create a logging interceptor to log request and responses
	OkHttpClient client = new OkHttpClient();
	InetSocketAddress p = findProxy();
	if(p != null) {
		client.setProxy(new Proxy(Proxy.Type.HTTP,p));
	} else { 
		client.setProxy(Proxy.NO_PROXY); 
	}
	// Create and configure the Retrofit object
	RestAdapter retrofit = new RestAdapter.Builder().setEndpoint(authority)
			.setLogLevel(LogLevel.FULL).setLog(new RestAdapter.Log() {
				@Override
				public void log(String msg) {
					logger.debug(msg);
				}
			}).setClient(new OkClient(client)).build();

	// Generate the token service
	return retrofit.create(TokenService.class);
}
 
開發者ID:OwaNotifier,項目名稱:owa-notifier,代碼行數:28,代碼來源:RestfullAcessProxy.java

示例2: getRealOutlookService

import com.squareup.okhttp.OkHttpClient; //導入方法依賴的package包/類
public static OutlookService getRealOutlookService(String accessTokenSource, String userEmailSource) {
	// Create a request interceptor to add headers that belong on
	// every request
	final String userEmail = userEmailSource;
	final String accessToken = accessTokenSource;
	RequestInterceptor requestInterceptor = new RequestInterceptor() {
		@Override
		public void intercept(RequestFacade request) {
			request.addHeader("User-Agent", "owa-notifier-daemon");
			request.addHeader("client-request-id", UUID.randomUUID().toString());
			request.addHeader("return-client-request-id", "true");
			request.addHeader("Authorization", String.format("Bearer %s", accessToken));
			request.addHeader("Accept","application/json");

			if (userEmail != null && !userEmail.isEmpty()) {
				request.addHeader("X-AnchorMailbox", userEmail);
			}
		}
	};
	
	OkHttpClient client = new OkHttpClient();
	InetSocketAddress p = findProxy();
	if(p != null) {
		client.setProxy(new Proxy(Proxy.Type.HTTP,p));
	} else { 
		client.setProxy(Proxy.NO_PROXY); 
	}
	
	// Create and configure the Retrofit object
	RestAdapter restAdapter = new RestAdapter.Builder()
			// Retrofit retrofit = new Retrofit.Builder()
			.setEndpoint("https://graph.microsoft.com")
			/*
			 * .client(client)
			 * .addConverterFactory(JacksonConverterFactory.create())
			 */
			.setRequestInterceptor(requestInterceptor).setLogLevel(LogLevel.FULL).setLog(new RestAdapter.Log() {
				@Override
				public void log(String msg) {
					logger.debug(msg);
				}
			}).setClient(new OkClient(client)).build();

	// Generate the token service
	return restAdapter.create(OutlookService.class);
}
 
開發者ID:OwaNotifier,項目名稱:owa-notifier,代碼行數:47,代碼來源:RestfullAcessProxy.java


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