[英]Okhttp3 jar missing okio?
I am trying to make a simple Java program to upload a bunch of images I have to imgur.我正在尝试制作一个简单的 Java 程序来上传一堆我必须要 imgur 的图像。 But I am running into problem after problem and cannot just get okhttp to work.
但是我遇到了一个又一个问题,不能让 okhttp 正常工作。 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:这在 RequestBody.create() 部分给出了错误:
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.当谷歌搜索这个错误时,我发现这个页面说我缺少 okio 库。 I thought this would be included with the okhttp jar.
我认为这将包含在 okhttp jar 中。 I download the okio jar anyway and add it to my project, but the error doesn't change.
无论如何,我下载了 okio jar 并将其添加到我的项目中,但错误没有改变。 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.如果您使用的是 Maven,则下载两个 Jars 并添加到您的 /lib。 Make sure your classpath and your IDE both point to these libs.
确保您的类路径和 IDE 都指向这些库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.