【发布时间】:2018-10-27 02:02:15
【问题描述】:
我想在服务器上上传数据以及音频文件,但我在过去两天遇到同样的错误
这是我的界面
@Multipart
@POST("index.php")
Call<Result> uploadFile(@Part("client_phone") String phn,
@Part("call_type") String Ststus,
@Part("start_time") String Stime,
@Part("end_time") String Etime,
@Part MultipartBody.Part body,
@Part("employe_phone") String emphn);
这是我的改造课
private static final String ROOT_URL ="http://192.168.0.113/recorder/api/";
public RetroClient() {
}
/**
* Get Retro Client
*
* @return JSON Object
*/
private static Retrofit getRetroClient() {
Gson gson = new GsonBuilder().setLenient().create();
return new Retrofit.Builder()
.baseUrl(ROOT_URL)
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
}
public static ApiService getApiService() {
return getRetroClient().create(ApiService.class);
}
这是对 API 的调用
RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), file);
// MultipartBody.Part is used to send also the actual file name
MultipartBody.Part body =
MultipartBody.Part.createFormData("uploaded_file", file.getName(), requestFile);
Misscall ms=new Misscall("7276367824","IN","2016-12-12_12:12:12","2016-12-12_12:13:03","7276367824");
Gson gson=new Gson();
String json=gson.toJson(ms);
Log.i(MyApp.TAG, "Object Json"+ms);
//Call<Result> resultCall = service.uploadFile(map,body);
Call<Result> resultCall = service.uploadFile("7276367824","IN","123456","1234567",body,"7276367824");
请帮帮我 提前致谢
【问题讨论】:
-
你解决了吗?