【问题标题】:OkHTTP error cannot access ByteStringOkHTTP 错误无法访问 ByteString
【发布时间】:2016-02-11 01:04:01
【问题描述】:

我正在使用 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 fun android studio show syntax error cannot resolve symbol okio

【问题讨论】:

    标签: android okhttp3


    【解决方案1】:

    如果添加两个库,您可以解决它。您可以查看 okhttp3 依赖项以检查您需要哪些库,在本例中为 okio。

        <dependency>
            <groupId>com.squareup.okhttp3</groupId>
            <artifactId>okhttp</artifactId>
            <version>4.9.3</version>
        </dependency>
        <dependency>
            <groupId>com.squareup.okio</groupId>
            <artifactId>okio</artifactId>
            <version>2.8.0</version>
            <scope>compile</scope>
        </dependency>
    

    【讨论】:

      【解决方案2】:

      这是一个单独的包,我们需要自己包含。名字是:奥基奥。

      你可以在这里找到最新的jar或java文件:https://github.com/square/okio

      【讨论】:

        【解决方案3】:

        您好,您可以将库 okio 添加到您的项目中。

        下载Latest version

        【讨论】:

          猜你喜欢
          • 2016-05-11
          • 2021-03-27
          • 2019-01-21
          • 2018-03-02
          • 1970-01-01
          • 1970-01-01
          • 2017-09-07
          • 2021-01-22
          • 2017-04-26
          相关资源
          最近更新 更多