本文整理汇总了Java中com.squareup.okhttp.Call.enqueue方法的典型用法代码示例。如果您正苦于以下问题:Java Call.enqueue方法的具体用法?Java Call.enqueue怎么用?Java Call.enqueue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.squareup.okhttp.Call
的用法示例。
在下文中一共展示了Call.enqueue方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: post
import com.squareup.okhttp.Call; //导入方法依赖的package包/类
Call post(Callback callback) throws IOException {
OkHttpClient client = getUnsafeOkHttpClient();
CookieManager cookieManager = new CookieManager();
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
client.setCookieHandler(cookieManager);
RequestBody requestBody = new FormEncodingBuilder()
.add("user_id", NetId)
.add("user_password", password)
.build();
Request request = new Request.Builder()
.url("https://studentmaintenance.webapps.snu.edu.in/students/public/studentslist/studentslist/loginauth")
.post(requestBody)
.build();
Call call = client.newCall(request);
call.enqueue(callback);
return call;
}
示例2: enqueue
import com.squareup.okhttp.Call; //导入方法依赖的package包/类
@Override
public void enqueue(final Request request,final Callback<Response> callback) {
Call call = mClient.newCall(makeRequest(request));
request.handle().setHandle(new CallHandle(call));
com.squareup.okhttp.Callback ok2Callback = new com.squareup.okhttp.Callback() {
@Override
public void onFailure(com.squareup.okhttp.Request okReq, IOException e) {
Exception throwable;
if("Canceled".equals(e.getMessage())){
throwable = new CanceledException(e);
}else{
throwable = e;
}
callback.onFailed(request,throwable);
}
@Override
public void onResponse(com.squareup.okhttp.Response response) throws IOException {
callback.onSuccess(request,response.headers().toMultimap(),new OkResponse(response,request));
}
};
call.enqueue(ok2Callback);
}
示例3: post
import com.squareup.okhttp.Call; //导入方法依赖的package包/类
/**
* Send POST request to the server to log the user in or out.
*
* @param mode Mode is used by the server script to differentiate between login and logout.
* 191: Login
* 193: Logout
* @param username The username of user
* @param password The password of user
* @param callback The Callback
* @return Call object
* @throws IOException
*/
Call post(String mode, String username, String password, Callback callback) throws IOException {
OkHttpClient client = new OkHttpClient();
RequestBody formBody = new FormEncodingBuilder()
.add("mode", mode)
.add("username", username + "@snu.in")
.add("password", password)
.build();
Request request = new Request.Builder()
.url("http://192.168.50.1/24online/servlet/E24onlineHTTPClient")
.post(formBody)
.build();
Call call = client.newCall(request);
call.enqueue(callback);
return call;
}
示例4: post
import com.squareup.okhttp.Call; //导入方法依赖的package包/类
public static Call post(String url, Map<String, String> params, Object tag, OkHttpCallback responseCallback) {
Request.Builder builder = new Request.Builder().url(url);
if (tag != null) {
builder.tag(tag);
}
FormEncodingBuilder encodingBuilder = new FormEncodingBuilder();
if (params != null && params.size() > 0) {
for (String key : params.keySet()) {
encodingBuilder.add(key, params.get(key));
}
}
RequestBody formBody = encodingBuilder.build();
builder.post(formBody);
Request request = builder.build();
Call call = getInstance().newCall(request);
call.enqueue(responseCallback);
return call;
}
示例5: post
import com.squareup.okhttp.Call; //导入方法依赖的package包/类
Call post(String url, String json, Callback callback) {
RequestBody body = RequestBody.create(JSON, json);
Request request = new Request.Builder()
.addHeader("Content-Type","application/json")
.addHeader("Authorization","key=AIzaSyAkeFnKc_r6TJSO7tm5OVnzkbni6dEk4Lw")
.url(url)
.post(body)
.build();
Call call = client.newCall(request);
call.enqueue(callback);
return call;
}
示例6: post
import com.squareup.okhttp.Call; //导入方法依赖的package包/类
Call post(String mode, String username, String password, Callback callback) throws IOException {
OkHttpClient client = new OkHttpClient();
RequestBody formBody = new FormEncodingBuilder()
.add("mode", mode)
.add("username", username + "@snu.in")
.add("password", password)
.build();
Request request = new Request.Builder()
.url("http://192.168.50.1/24online/servlet/E24onlineHTTPClient")
.post(formBody)
.build();
Call call = client.newCall(request);
call.enqueue(callback);
return call;
}
示例7: fillFutureCache
import com.squareup.okhttp.Call; //导入方法依赖的package包/类
/**
* Makes async segment requests to fill the cache up to a certain level.
*/
private synchronized void fillFutureCache(Representation representation) {
int segmentsToBuffer = (int)Math.ceil((double)mMinBufferTimeUs / mRepresentation.segmentDurationUs);
for(int i = mCurrentSegment + 1; i < Math.min(mCurrentSegment + 1 + segmentsToBuffer, mRepresentation.segments.size()); i++) {
if(!mFutureCache.containsKey(i) && !mFutureCacheRequests.containsKey(i)) {
Segment segment = representation.segments.get(i);
Request request = buildSegmentRequest(segment);
Call call = mHttpClient.newCall(request);
CachedSegment cachedSegment = new CachedSegment(i, segment, representation); // segment could be accessed through representation by i
call.enqueue(new SegmentDownloadCallback(cachedSegment));
mFutureCacheRequests.put(i, call);
}
}
}
示例8: newRequestCall
import com.squareup.okhttp.Call; //导入方法依赖的package包/类
private void newRequestCall(Callback callback, String url, RequestBody requestBody) {
Request request = new Request.Builder()
.url(url)
.post(requestBody)
.build();
Call call = mOkHttpClient.newCall(request);
call.enqueue(callback);
}
示例9: get
import com.squareup.okhttp.Call; //导入方法依赖的package包/类
public static Call get(String url, Object tag, OkHttpCallback responseCallback) {
Request.Builder builder = new Request.Builder().url(url);
if (tag != null) {
builder.tag(tag);
}
Request request = builder.build();
Call call = getInstance().newCall(request);
call.enqueue(responseCallback);
return call;
}
示例10: request
import com.squareup.okhttp.Call; //导入方法依赖的package包/类
void request(RequestType mRequestType, OkHttpClient mOkHttpClient, String url, Header[] headers, Object tag, BaseApiHandler baseHandler) {
Request.Builder mBuilder = new Request.Builder();
mBuilder.url(url);
if (mRequestType == RequestType.GET) {
mBuilder.get();
} else {
mBuilder.post(null);
}
if (headers != null) {
Headers.Builder mHB = new Headers.Builder();
for (int i = 0; i < headers.length; i++) {
String value = headers[i].getValue();
String key = headers[i].getName();
mHB.add(key, value);
}
Headers mHeader = mHB.build();
mBuilder.headers(mHeader);
}
mBuilder.tag(tag);
Call mCall = mOkHttpClient.newCall(mBuilder.build());
mCall.enqueue(baseHandler);
}
示例11: get
import com.squareup.okhttp.Call; //导入方法依赖的package包/类
public static Call get(String url, Callback callback) {
Request request = new Request.Builder().url(url).build();
Call call = getHttpClient().newCall(request);
call.enqueue(callback);
return call;
}
示例12: post
import com.squareup.okhttp.Call; //导入方法依赖的package包/类
public static Call post(String url, RequestBody body, Callback callback) {
Request request = new Request.Builder().url(url).post(body).build();
Call call = getHttpClient().newCall(request);
call.enqueue(callback);
return call;
}
示例13: send
import com.squareup.okhttp.Call; //导入方法依赖的package包/类
@Override
public void send(final URL webhookUrl, final String payload) {
Request request = new Builder().url(webhookUrl).post(RequestBody.create(JSON, payload)).build();
Call call = okHttpClient.newCall(request);
call.enqueue(RESPONSE_CALLBACK);
}