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;
}
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;
}
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);
}
});
}
Aggregations