public SixRequest() {
    builder = new FormBody.Builder();
    handler = new Handler(Looper.getMainLooper());

    // add common params
    builder.add("platform", "android");
    builder.add("deviceId", "deviceID");
    builder.add("accessToken", "token");
    builder.add("timestamp", "" + System.currentTimeMillis());
    builder.add("version", "v1.0");
  }
Exemple #2
0
  @Override
  protected Request searchMangaRequest(MangasPage page, String query) {
    if (page.page == 1) {
      page.url = getInitialSearchUrl(query);
    }

    FormBody.Builder form = new FormBody.Builder();
    form.add("authorArtist", "");
    form.add("mangaName", query);
    form.add("status", "");
    form.add("genres", "");

    return ReqKt.post(page.url, getRequestHeaders(), form.build());
  }
 private void addParams(FormBody.Builder builder) {
   if (params != null) {
     for (String key : params.keySet()) {
       builder.add(key, params.get(key));
     }
   }
 }
Exemple #4
0
  /**
   * post请求
   *
   * @param tag
   * @param url
   * @param headers
   * @param params
   * @param postCallBack
   */
  public static void post(
      Object tag,
      String url,
      Map<String, String> headers,
      Map<String, String> params,
      final PostCallBack postCallBack) {
    Logger.i(TAG, "post url :" + url);
    setCancel(false);
    RequestBody requestBody = null;
    FormBody.Builder formBodyBuilder = new FormBody.Builder();
    if (params == null || params.size() == 0) {
      requestBody = formBodyBuilder.build();
    } else {
      for (Map.Entry<String, String> me : params.entrySet()) {
        formBodyBuilder.add(me.getKey(), me.getValue());
      }
      requestBody = formBodyBuilder.build();
    }
    Request.Builder requestBuilder = new Request.Builder();
    requestBuilder.tag(tag);
    requestBuilder.url(url);
    appendHeaders(requestBuilder, headers);
    requestBuilder.post(requestBody);
    Request request = requestBuilder.build();
    mCall = mClient.newCall(request);
    mCalls.add(mCall);
    mCall.enqueue(
        new Callback() {
          @Override
          public void onFailure(Call call, IOException e) {
            Logger.e(TAG, "post onFailure :" + e.toString());
            postCallBack.onFailure(call, e);
            EventBus.getDefault().post(new NetWorkBadEvent());
          }

          @Override
          public void onResponse(Call call, Response response) throws IOException {
            if (response.isSuccessful()) {
              Logger.i(TAG, "post onResponse");
              postCallBack.onResponse(call, response);
            } else {
              Logger.i(TAG, "post onError: " + response.code());
              postCallBack.onError(response.code());
            }
          }
        });
  }
Exemple #5
0
 @Deprecated
 private Request buildPostFormRequest(
     String url, WeakHashMap<String, String> params, Object... tag) {
   FormBody.Builder builder = new FormBody.Builder();
   Iterator<Map.Entry<String, String>> entries = params.entrySet().iterator();
   while (entries.hasNext()) {
     Map.Entry<String, String> entry = entries.next();
     builder.add(entry.getKey(), entry.getValue());
   }
   RequestBody formBody = builder.build();
   Request.Builder requestBuilder = new Request.Builder();
   requestBuilder.url(url);
   requestBuilder.post(formBody);
   if (tag.length > 0) {
     requestBuilder.tag(tag[0]);
   }
   return requestBuilder.build();
 }
 public void addParam(String key, String value) {
   builder.add(key, value);
 }