當前位置: 首頁>>代碼示例>>Java>>正文


Java Request類代碼示例

本文整理匯總了Java中com.squareup.okhttp.Request的典型用法代碼示例。如果您正苦於以下問題:Java Request類的具體用法?Java Request怎麽用?Java Request使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Request類屬於com.squareup.okhttp包,在下文中一共展示了Request類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createOpenCellIdApiCall

import com.squareup.okhttp.Request; //導入依賴的package包/類
private Request createOpenCellIdApiCall() {
    StringBuilder sb = new StringBuilder();
    sb.append("http://www.opencellid.org/cell/get?key=").append(CellTracker.OCID_API_KEY);

    if (mAimsicdService.getCell().getMCC() != Integer.MAX_VALUE) {
        sb.append("&mcc=").append(mAimsicdService.getCell().getMCC());
    }
    if (mAimsicdService.getCell().getMNC() != Integer.MAX_VALUE) {
        sb.append("&mnc=").append(mAimsicdService.getCell().getMNC());
    }
    if (mAimsicdService.getCell().getLAC() != Integer.MAX_VALUE) {
        sb.append("&lac=").append(mAimsicdService.getCell().getLAC());
    }
    if (mAimsicdService.getCell().getCID() != Integer.MAX_VALUE) {
        sb.append("&cellid=").append(mAimsicdService.getCell().getCID());
    }
    sb.append("&format=json");
    return new Request.Builder()
            .url(sb.toString())
            .get()
            .build();
}
 
開發者ID:5GSD,項目名稱:AIMSICDL,代碼行數:23,代碼來源:DeviceFragment.java

示例2: fetch

import com.squareup.okhttp.Request; //導入依賴的package包/類
@Override
public void fetch(final OkHttpNetworkFetchState fetchState, final Callback callback) {
  fetchState.submitTime = SystemClock.uptimeMillis();
  final Uri uri = fetchState.getUri();

  try {
    Request request = new Request.Builder()
      .cacheControl(new CacheControl.Builder().noStore().build())
      .url(uri.toString())
      .get()
      .build();
    fetchWithRequest(fetchState, callback, request);
  } catch (Exception e) {
    // handle error while creating the request
    callback.onFailure(e);
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:18,代碼來源:OkHttpNetworkFetcher.java

示例3: shouldSendGetRequestAndReceiveException

import com.squareup.okhttp.Request; //導入依賴的package包/類
@Test
public void shouldSendGetRequestAndReceiveException() {
  final Request request = new com.squareup.okhttp.Request.Builder()
      .url(URI)
      .method("GET", null)
      .build();
  when(okHttpClient.newCall(argThat(new RequestMatcher(request)))).thenReturn(call);
  doAnswer(invocation -> {
    final Callback callback = invocation.getArgument(0);
    callback.onFailure(request, new IOException());
    return Void.TYPE;
  }).when(call).enqueue(isA(Callback.class));
  final CompletionStage<com.spotify.apollo.Response<ByteString>> response =
      client.send(com.spotify.apollo.Request.forUri(URI, "GET").withTtl(Duration.ofMillis(100)));
  verify(okHttpClient).setReadTimeout(100, TimeUnit.MILLISECONDS);
  assertTrue(response.toCompletableFuture().isCompletedExceptionally());
}
 
開發者ID:honnix,項目名稱:rkt-launcher,代碼行數:18,代碼來源:ClientTest.java

示例4: doInBackground

import com.squareup.okhttp.Request; //導入依賴的package包/類
@Override
protected Void doInBackground(Void... params) {

    try {
        Request.Builder requestBuilder = new Request.Builder()
                .url(serverAddr + urlPart);
        switch (method) {
            case PUT:
                requestBuilder.put(RequestBody.create(MEDIA_TYPE_JSON, json));
                break;
            case POST:
                requestBuilder.post(RequestBody.create(MEDIA_TYPE_JSON, json));
                break;
            case DELETE:
                requestBuilder.delete(RequestBody.create(MEDIA_TYPE_JSON, json));
                break;
            default: break;
        }
        Request request = requestBuilder.build();
        httpClient.newCall(request).enqueue(new HttpCallback(callback));
    } catch (Exception e) {
        Log.e(TAG, "IOException", e);
    }
    return null;
}
 
開發者ID:uncleashi,項目名稱:find-client-android,代碼行數:26,代碼來源:FindWiFiImpl.java

示例5: testWildfly

import com.squareup.okhttp.Request; //導入依賴的package包/類
/**
 * Run some HTTP queries against a Docker container from image promagent/wildfly-kitchensink-promagent.
 * <p/>
 * The Docker container is started by the maven-docker-plugin when running <tt>mvn verify -Pwildfly</tt>.
 */
@Test
public void testWildfly() throws Exception {
    OkHttpClient client = new OkHttpClient();
    Request restRequest = new Request.Builder().url(System.getProperty("deployment.url") + "/rest/members").build();

    // Execute REST call
    Response restResponse = client.newCall(restRequest).execute();
    Assertions.assertEquals(restResponse.code(), 200);
    Assertions.assertTrue(restResponse.body().string().contains("John Smith"));

    Thread.sleep(100); // metric is incremented after servlet has written the response, wait a little to get the updated metric
    assertMetrics(client, "1.0");

    // Execute REST call again
    restResponse = client.newCall(restRequest).execute();
    Assertions.assertEquals(restResponse.code(), 200);
    Assertions.assertTrue(restResponse.body().string().contains("John Smith"));

    Thread.sleep(100); // metric is incremented after servlet has written the response, wait a little to get the updated metric
    assertMetrics(client, "2.0");
}
 
開發者ID:fstab,項目名稱:promagent,代碼行數:27,代碼來源:WildflyIT.java

示例6: doInBackground

import com.squareup.okhttp.Request; //導入依賴的package包/類
/**
 *
 * @param params
 * @return
 */
@Override
protected String doInBackground(Void... params) {
    OkHttpClient client = new OkHttpClient();

    HttpUrl httpUrl = HttpUrl.parse(COIN_DESK_API_URL);
    //System.out.println("Requesting : " + httpUrl.toString());

    FormEncodingBuilder formBody = new FormEncodingBuilder();
    formBody.add("lastHours", "24");
    formBody.add("maxRespArrSize", "24");

    Request request = new Request.Builder()
            .url(httpUrl)
            .post(formBody.build())
            .build();

    String content = null;
    try {
        Response response = client.newCall(request).execute();
        ResponseBody body = response.body();

        if (isZipped(response)) {
            content = unzip(body);
        } else {
            content = body.string();
        }

        body.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return content;
}
 
開發者ID:ehanoc,項目名稱:xwallet,代碼行數:40,代碼來源:CexChartAPI.java

示例7: connect

import com.squareup.okhttp.Request; //導入依賴的package包/類
public void connect(String url) {
  try {
    mHttpClient= (OkHttpClient) Class.forName("com.squareup.okhttp.OkHttpClient").newInstance();
  } catch (Exception e) {
    isSupportWebSocket =false;
    return;
  }
  mHttpClient.setConnectTimeout(10, TimeUnit.SECONDS);
  mHttpClient.setWriteTimeout(10, TimeUnit.SECONDS);
  // Disable timeouts for read
  mHttpClient.setReadTimeout(0, TimeUnit.MINUTES);

  Request request = new Request.Builder().url(url).build();
  WebSocketCall call = WebSocketCall.create(mHttpClient, request);
  call.enqueue(this);
}
 
開發者ID:amap-demo,項目名稱:weex-3d-map,代碼行數:17,代碼來源:WXWebSocketManager.java

示例8: onOpen

import com.squareup.okhttp.Request; //導入依賴的package包/類
@Override
public void onOpen(WebSocket webSocket, Request arg1, Response arg2)
    throws IOException {
  mWebSocket = webSocket;
  setEnvironment(WXEnvironment.getConfig());
  WXSDKManager.getInstance().postOnUiThread(new Runnable() {
    @Override
    public void run() {
      Toast.makeText(WXEnvironment.sApplication, "Has switched to DEBUG mode, you can see the DEBUG information on the browser!", Toast.LENGTH_SHORT).show();
    }
  },0);
  for (JSDebuggerCallback callback : mCallbacks.values()) {
    callback.onSuccess(arg2);
  }
  WXLogUtils.e("into--[onOpen]");
}
 
開發者ID:amap-demo,項目名稱:weex-3d-map,代碼行數:17,代碼來源:WXWebSocketManager.java

示例9: onOkHttpNew

import com.squareup.okhttp.Request; //導入依賴的package包/類
@Around("call(* com.squareup.okhttp.OkHttpClient+.newCall(..))")
public Object onOkHttpNew(ProceedingJoinPoint joinPoint) throws Throwable {
    if (!Configuration.httpMonitorEnable || joinPoint.getArgs().length != 1) {
        return joinPoint.proceed();
    }
    Object[] args = joinPoint.getArgs();
    Request request = (Request) args[0];

    //url
    URL url = request.url();
    if (GlobalConfig.isExcludeHost(url.getHost())) {
        return joinPoint.proceed();
    }
    RespBean bean = new RespBean();
    bean.setUrl(url.toString());
    bean.setStartTimestamp(System.currentTimeMillis());
    startTimeStamp.add(bean);
    return joinPoint.proceed();
}
 
開發者ID:pre-dem,項目名稱:pre-dem-android,代碼行數:20,代碼來源:OkHttp2Probe.java

示例10: get

import com.squareup.okhttp.Request; //導入依賴的package包/類
public static long get(String collection, String user) {
    try {
        collection = "lists." + Long.parseLong(collection);
    } catch (NumberFormatException ignored) {

    }

    Request request = new Request.Builder()
            .url(TWEETMARKER_API_URL + "?api_key=" + API_KEY + "&username=" + user + "&collection" + collection)
            .get()
            .build();

    try {
        final Response response = createHttpClientWithoutSSL().newCall(request).execute();
        JSONObject json = new JSONObject(response.body().string());
        return json.getJSONObject(collection).getLong("id");
    } catch (IOException | JSONException | NoSuchAlgorithmException | KeyManagementException e) {
        Timber.i(e, "");
    }

    return -1;
}
 
開發者ID:mecid,項目名稱:robird-reborn,代碼行數:23,代碼來源:TweetMarkerUtils.java

示例11: writeRequestHeaders

import com.squareup.okhttp.Request; //導入依賴的package包/類
public void writeRequestHeaders(Request request) throws IOException {
    if (this.stream == null) {
        List<Header> requestHeaders;
        this.httpEngine.writingRequestHeaders();
        boolean permitsRequestBody = this.httpEngine.permitsRequestBody(request);
        if (this.framedConnection.getProtocol() == Protocol.HTTP_2) {
            requestHeaders = http2HeadersList(request);
        } else {
            requestHeaders = spdy3HeadersList(request);
        }
        this.stream = this.framedConnection.newStream(requestHeaders, permitsRequestBody, true);
        this.stream.readTimeout().timeout((long) this.httpEngine.client.getReadTimeout(),
                TimeUnit.MILLISECONDS);
        this.stream.writeTimeout().timeout((long) this.httpEngine.client.getWriteTimeout(),
                TimeUnit.MILLISECONDS);
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:18,代碼來源:Http2xStream.java

示例12: post

import com.squareup.okhttp.Request; //導入依賴的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;
}
 
開發者ID:anuragsai97,項目名稱:Library-Token-Automation,代碼行數:18,代碼來源:LoginActivity.java

示例13: networkRequest

import com.squareup.okhttp.Request; //導入依賴的package包/類
private Request networkRequest(Request request) throws IOException {
    Request.Builder result = request.newBuilder();
    if (request.header("Host") == null) {
        result.header("Host", Util.hostHeader(request.httpUrl()));
    }
    if (request.header("Connection") == null) {
        result.header("Connection", "Keep-Alive");
    }
    if (request.header(AsyncHttpClient.HEADER_ACCEPT_ENCODING) == null) {
        this.transparentGzip = true;
        result.header(AsyncHttpClient.HEADER_ACCEPT_ENCODING, AsyncHttpClient.ENCODING_GZIP);
    }
    CookieHandler cookieHandler = this.client.getCookieHandler();
    if (cookieHandler != null) {
        OkHeaders.addCookies(result, cookieHandler.get(request.uri(), OkHeaders.toMultimap
                (result.build().headers(), null)));
    }
    if (request.header(Network.USER_AGENT) == null) {
        result.header(Network.USER_AGENT, Version.userAgent());
    }
    return result.build();
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:23,代碼來源:HttpEngine.java

示例14: _getAsyn

import com.squareup.okhttp.Request; //導入依賴的package包/類
/**
 * 同步的Get請求
 *
 * @param url
 * @return Response
 */
private Response _getAsyn(String url) throws IOException {
    final Request request = new Request.Builder()
            .url(url)
            .build();
    Call call = mOkHttpClient.newCall(request);
    Response execute = call.execute();
    return execute;
}
 
開發者ID:NaOHAndroid,項目名稱:Logistics-guard,代碼行數:15,代碼來源:OkHttpClientManager.java

示例15: post

import com.squareup.okhttp.Request; //導入依賴的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;
}
 
開發者ID:anuragsai97,項目名稱:Library-Token-Automation,代碼行數:16,代碼來源:MainActivity.java


注:本文中的com.squareup.okhttp.Request類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。