当前位置: 首页>>代码示例>>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;未经允许,请勿转载。