Search in sources :

Example 1 with HttpRequest

use of com.qiyei.sdk.http.base.HttpRequest in project EssayJoke by qiyei2015.

the class OkHttpEngine method post.

@Override
public void post(HttpRequest httpRequest, final IHttpCallback callback) {
    RequestBody requestBody = buildPostRequest(httpRequest);
    Request request = new Request.Builder().url(httpRequest.getUrl()).post(requestBody).build();
    LogManager.e("Post请求路径:", httpRequest.getUrl());
    mClient.newCall(request).enqueue(new Callback() {

        @Override
        public void onFailure(Call call, IOException e) {
            callback.onFail(e);
        }

        @Override
        public void onResponse(Call call, Response response) throws IOException {
            if (response != null && response.isSuccessful()) {
                callback.onSuccess(response.body().string());
            } else {
                callback.onFail(new Exception("error"));
            }
        }
    });
}
Also used : Response(okhttp3.Response) Call(okhttp3.Call) Callback(okhttp3.Callback) IHttpCallback(com.qiyei.sdk.http.base.IHttpCallback) Request(okhttp3.Request) HttpRequest(com.qiyei.sdk.http.base.HttpRequest) IOException(java.io.IOException) IOException(java.io.IOException) RequestBody(okhttp3.RequestBody)

Example 2 with HttpRequest

use of com.qiyei.sdk.http.base.HttpRequest in project EssayJoke by qiyei2015.

the class BannerTestActivity method buildRequest.

private HttpRequest buildRequest() {
    HttpRequest request = new HttpRequest();
    request.setUrl("http://is.snssdk.com/2/essay/discovery/v3/");
    Map<String, Object> params = new HashMap<>();
    params.put("iid", "6152551759");
    params.put("aid", "7");
    params.put("channel", 360);
    addCommonParams(params);
    request.setParams(params);
    request.setRequestMethod(RequestMethod.GET);
    request.setUseCache(true);
    return request;
}
Also used : HttpRequest(com.qiyei.sdk.http.base.HttpRequest) HashMap(java.util.HashMap)

Example 3 with HttpRequest

use of com.qiyei.sdk.http.base.HttpRequest in project EssayJoke by qiyei2015.

the class FindFragment method buildRequest.

private HttpRequest buildRequest() {
    HttpRequest request = new HttpRequest();
    request.setUrl("http://is.snssdk.com/2/essay/discovery/v3/");
    Map<String, Object> params = new HashMap<>();
    params.put("iid", "6152551759");
    params.put("aid", "7");
    params.put("channel", 360);
    addCommonParams(params);
    request.setParams(params);
    request.setRequestMethod(RequestMethod.GET);
    request.setUseCache(true);
    return request;
}
Also used : HttpRequest(com.qiyei.sdk.http.base.HttpRequest) HashMap(java.util.HashMap)

Example 4 with HttpRequest

use of com.qiyei.sdk.http.base.HttpRequest in project EssayJoke by qiyei2015.

the class OkHttpEngine method get.

@Override
public void get(HttpRequest req, final IHttpCallback callback) {
    String url = HttpHelper.buildGetRequest(req);
    LogManager.e("Get请求路径:", url);
    okhttp3.Request.Builder builder = new okhttp3.Request.Builder().url(url);
    Request request = builder.build();
    mClient.newCall(request).enqueue(new Callback() {

        @Override
        public void onFailure(Call call, IOException e) {
            callback.onFail(e);
        }

        @Override
        public void onResponse(Call call, Response response) throws IOException {
            if (response != null && response.isSuccessful()) {
                callback.onSuccess(response.body().string());
            } else {
                callback.onFail(new Exception("error"));
            }
        }
    });
}
Also used : Response(okhttp3.Response) Call(okhttp3.Call) Callback(okhttp3.Callback) IHttpCallback(com.qiyei.sdk.http.base.IHttpCallback) Request(okhttp3.Request) HttpRequest(com.qiyei.sdk.http.base.HttpRequest) IOException(java.io.IOException) IOException(java.io.IOException)

Aggregations

HttpRequest (com.qiyei.sdk.http.base.HttpRequest)4 IHttpCallback (com.qiyei.sdk.http.base.IHttpCallback)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Call (okhttp3.Call)2 Callback (okhttp3.Callback)2 Request (okhttp3.Request)2 Response (okhttp3.Response)2 RequestBody (okhttp3.RequestBody)1