MediaType parse = MediaType.parse("application/octet-stream");
RequestBody cc = RequestBody.create(parse, "cc");
File file =new File("/storage/sdcard0/Pictures/music1.mp3");
final RequestBody requestBody = RequestBody.create(parse, file);
MultipartBody.Part file1 = MultipartBody.Part.createFormData("file", file.getName(), requestBody);
if (file.exists()) {
Retrofit retrofit =new Retrofit.Builder()
.baseUrl("http://yun918.cn/")
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build();
ApiSerView apiSerView = retrofit.create(ApiSerView.class);
Observable getretrofitdata = apiSerView.getretrofitdata(file1, cc);
getretrofitdata.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(ResponseBody responseBody) {
try {
String s = responseBody.string();
Log.i("aa", "onNext: " + s);
}catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
});
}
网友评论