本文整理汇总了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);
}
示例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);
}