Retrofit上传单个文件出错,Unknown bits set in runtime_flags: 0x8000
public void postFile(View view){
//API mApi= RetrofitManger.getRetrofit().create(API.class);
if(Path.size()==0){
Toast.makeText(this,"未选择图片!",Toast.LENGTH_SHORT).show();
}
else {
File file = new File(Path.get(0));
Retrofit retrofit=new Retrofit.Builder()
.baseUrl("http://localhost:9102")
.addConverterFactory(GsonConverterFactory.create())
.build();
mApi= retrofit.create(API.class);
RequestBody body = RequestBody.create(MediaType.parse("image/jepg"), file);
MultipartBody.Part part = MultipartBody.Part.createFormData("file", Path.get(0), body);
Call<PostFileResult> task = mApi.postFile(part);
task.enqueue(new Callback<PostFileResult>() {
@Override
public void onResponse(Call<PostFileResult> call, Response<PostFileResult> response) {
int code = response.code();
if (HttpURLConnection.HTTP_OK == code) {
Log.d(TAG, "result -- >" + response.body());
}
}
@Override
public void onFailure(Call<PostFileResult> call, Throwable t) {
Log.d(TAG, "onFailure -- >" + t.toString());
}
});
- }非计算机专业学生,毕业设计需要设计APP,上传图片到服务器,使用Retrofit上传后出错,跟着视频教程敲的代码,请大神帮忙看看问题出在哪里。
- logcat如下
先用postMan模拟请求,确定后台没有问题,再去做android的代码。