Search in sources :

Example 71 with Request

use of com.squareup.okhttp.Request in project weex-example by KalicyZhou.

the class HotRefreshManager method connect.

public boolean connect(String url) {
    OkHttpClient httpClient = new OkHttpClient();
    Request request = new Request.Builder().url(url).addHeader("sec-websocket-protocol", "echo-protocol").build();
    WebSocketCall.create(httpClient, request).enqueue(new WXWebSocketListener(url));
    return true;
}
Also used : OkHttpClient(com.squareup.okhttp.OkHttpClient) Request(com.squareup.okhttp.Request)

Example 72 with Request

use of com.squareup.okhttp.Request in project ignite by apache.

the class IgniteCamelStreamerTest method sendMessages.

/**
 * @throws IOException
 * @return HTTP response payloads.
 */
private List<String> sendMessages(int fromIdx, int cnt, boolean singleMessage) throws IOException {
    List<String> responses = Lists.newArrayList();
    if (singleMessage) {
        StringBuilder sb = new StringBuilder();
        for (int i = fromIdx; i < fromIdx + cnt; i++) sb.append(i).append(",").append(TEST_DATA.get(i)).append("\n");
        Request request = new Request.Builder().url(url).post(RequestBody.create(TEXT_PLAIN, sb.toString())).build();
        Response response = httpClient.newCall(request).execute();
        responses.add(response.body().string());
    } else {
        for (int i = fromIdx; i < fromIdx + cnt; i++) {
            String payload = i + "," + TEST_DATA.get(i);
            Request request = new Request.Builder().url(url).post(RequestBody.create(TEXT_PLAIN, payload)).build();
            Response response = httpClient.newCall(request).execute();
            responses.add(response.body().string());
        }
    }
    return responses;
}
Also used : Response(com.squareup.okhttp.Response) Request(com.squareup.okhttp.Request) Endpoint(org.apache.camel.Endpoint)

Example 73 with Request

use of com.squareup.okhttp.Request in project Mvp-Rxjava-Retrofit-dagger2 by pengMaster.

the class MediaRecordPresenter method downLoadVideo.

/**
 * 1.视频已存在 加载本地视频
 * 2.视频不存在  下载
 *
 * @param fileUrl     下载地址
 * @param name        视频名字
 * @param progressBar 进度条
 */
public void downLoadVideo(String fileUrl, String name, final ProgressBar progressBar) {
    String packagePath = FileUtils.getPackagePath(mApplication) + "/video/";
    boolean dirs = FileUtils.createDirs(packagePath);
    if (!dirs) {
        mRootView.showMessage("文件夹创建失败");
    }
    String videoPath = packagePath + name;
    File videoFile = new File(videoPath);
    if (videoFile.exists()) {
        mRootView.startVideo(videoFile);
        return;
    } else {
        progressBar.setVisibility(View.VISIBLE);
        progressBar.setMax(100);
    }
    OkHttpUtils.get().url(fileUrl).addParams("", "").build().execute(new FileCallBack(packagePath, name) {

        @Override
        public void inProgress(float progress) {
            int i = (int) (progress * 100);
            progressBar.setProgress(i);
        }

        @Override
        public void onError(Request request, Exception e) {
            progressBar.setVisibility(View.GONE);
            e.printStackTrace();
        }

        @Override
        public void onResponse(File response) {
            progressBar.setVisibility(View.GONE);
            mRootView.startVideo(response);
        }
    });
}
Also used : FileCallBack(com.zhy.http.okhttp.callback.FileCallBack) Request(com.squareup.okhttp.Request) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException)

Aggregations

Request (com.squareup.okhttp.Request)73 Response (com.squareup.okhttp.Response)47 IOException (java.io.IOException)41 OkHttpClient (com.squareup.okhttp.OkHttpClient)22 RequestBody (com.squareup.okhttp.RequestBody)18 UnsupportedEncodingException (java.io.UnsupportedEncodingException)12 FormEncodingBuilder (com.squareup.okhttp.FormEncodingBuilder)11 File (java.io.File)10 Callback (com.squareup.okhttp.Callback)9 InputStream (java.io.InputStream)6 Gson (com.google.gson.Gson)4 SpringAndroidSpiceRequest (com.octo.android.robospice.request.springandroid.SpringAndroidSpiceRequest)4 MediaType (com.squareup.okhttp.MediaType)4 ResponseBody (com.squareup.okhttp.ResponseBody)4 FileOutputStream (java.io.FileOutputStream)4 Intent (android.content.Intent)3 SharedPreferences (android.content.SharedPreferences)3 Uri (android.net.Uri)3 Cache (com.squareup.okhttp.Cache)3 Call (com.squareup.okhttp.Call)3