当前位置: 首页>>代码示例>>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;未经允许,请勿转载。