简体   繁体   中英

Okhttp3 jar missing okio?

I am trying to make a simple Java program to upload a bunch of images I have to imgur. But I am running into problem after problem and cannot just get okhttp to work. At this point the time I have spent trying to solve this has been way longer than it will take for me to write the program itself. I am very new to this kind of stuff so be patient with me please.

So, right now I have the following code from this tutorial :

RequestBody requestBody = new MultipartBody.Builder()
                .addFormDataPart("new", "This is my new TODO")
                .addFormDataPart("image", "attachment.png",
                        RequestBody.create(new File(""), MediaType.parse("image/png"))
                )
                .setType(MultipartBody.FORM)
                .build();

Which is giving an error on the RequestBody.create() part:

The type okio.ByteString cannot be resolved. It is indirectly referenced from required .class files

When Googling this error, I find this page which says I'm missing the okio library. I thought this would be included with the okhttp jar. I download the okio jar anyway and add it to my project, but the error doesn't change. I have no idea what else might be wrong.

Since it is a learning exercise, use the latest:

<dependency>
    <groupId>com.squareup.okio</groupId>
    <artifactId>okio</artifactId>
    <version>3.0.0</version>
</dependency>

<dependency>
    <groupId>com.squareup.okhttp</groupId>
    <artifactId>okhttp</artifactId>
    <version>2.7.5</version>
</dependency>

If you are using Maven, otherwise download both Jars and add to your /lib. Make sure your classpath and your IDE both point to these libs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM