我正在使用OkHttp库来进行多部分数据,一切都很好我没有任何错误但是当我编译程序时它会给我错误
错误:(172,40)错误:无法访问ByteString 找不到okio.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有趣的android studio show语法错误cannot resolve symbol okio
答案 0 :(得分:11)
这是我们需要自己包含的独立包装。名字是:Okio。
您可以在此处找到最新的jar或java文件:https://github.com/square/okio
答案 1 :(得分:0)
您好,您可以将libs okio添加到您的项目中。