我正在使用 OkHttp 库来处理多部分数据,一切都很好,我没有任何错误,但是当我编译程序时,它给了我错误
错误:(172, 40) 错误:无法访问 okio.ByteString 的 ByteString 类文件未找到
错误发生在这里RequestBody.create(MEDIA_TYPE_JPG, new File(data.getFileParam())))
这是实现多部分请求的方法的完整代码
public static String makeRequest(RequestConstructor data, String a, String b) {
final MediaType MEDIA_TYPE_JPG = MediaType.parse("image/jpg");
try {
OkHttpClient client = new OkHttpClient();
Log.d("test",data.getFileParam());
RequestBody requestBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("bunting", data.getParam("bunting"))
.addFormDataPart("dangler", data.getParam("dangler"))
.addFormDataPart("poster", data.getParam("poster"))
.addFormDataPart("tearPad", data.getParam("tearPad"))
.addFormDataPart("leafLet", data.getParam("leafLet"))
.addFormDataPart("outlet_category", "")
.addFormDataPart("dealerName", data.getParam("dealerName"))
.addFormDataPart("brouchers", data.getParam("brouchers"))
.addFormDataPart("wobblers", data.getParam("wobblers"))
.addFormDataPart("tentCard", data.getParam("tentCard"))
.addFormDataPart("others", data.getParam("others"))
.addFormDataPart("photo", "1.jpg",
RequestBody.create(MEDIA_TYPE_JPG, new File(data.getFileParam())))
.build();
Request request = new Request.Builder()
.url(data.getUrl())
.post(requestBody)
.build();
Response response = client.newCall(request).execute();
if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
Log.d("From OkHTTP Response", response.toString());
System.out.println(response.body().string());
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
我没有任何 okio 类的导入,所以我尝试添加 manully fun android studio show syntax errorcannot resolve symbol okio