- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我在我的应用程序 OkHttp 库 ( http://square.github.io/okhttp/ ) 中使用,在一个简单的 GET 请求中我得到了这个异常:
Caused by: java.io.EOFException: \n not found: size=0 content=...
at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:201)
at com.squareup.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:191)
...
unexpected end of stream on Connection{th.it-bedna.cz:80, proxy=DIRECT@ hostAddress=85.118.128.42 cipherSuite=none protocol=http/1.1} (recycle count=0)
对同一地址的其他 Get 请求工作正常。如果我向 Chrome 键入此请求,它也可以正常工作。你知道哪里出了问题吗?
感谢您的任何建议。
编辑:GET 的代码
public Call doGetRequest(String url, Callback callback) {
com.squareup.okhttp.Request request = new com.squareup.okhttp.Request.Builder()
.url(url)
.build();
Call call = client.newCall(request);
call.enqueue(callback);
return call;
}
使用:
void getData()
{
String url = "http://th.it-bedna.cz/api/v2/event/1/user?i=8";
Singleton.getInstance().doGetRequest(url, new Callback() {
@Override
public void onFailure(Request request, IOException e) {
Log.i("CDT", "onFailure: " + e);
}
@Override
public void onResponse(Response response) throws IOException {
}
});
}
最佳答案
如果您的服务器是 th.it-bedna.cz
,如您的 logcat 信息所示,您可以尝试以下代码:
OkHttpClient client = new OkHttpClient();
// GET request
Request request = new Request.Builder()
.url("http://th.it-bedna.cz")
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Request request, IOException e) {
Log.e(LOG_TAG, e.toString());
}
@Override
public void onResponse(Response response) throws IOException {
Log.w(LOG_TAG, response.body().string());
Log.i(LOG_TAG, response.toString());
}
});
关于java - Android OkHttp 库 : GET Request - Exception EOFException:\n not found: size=0 content=,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34072774/
我编写了以下客户端-服务器对来设置一个非常简化版本的 IPSec 连接(与加密相关)。 问题是,在第二次调用 readObject() 时,即: // Receive finished
我创建了一个 Talend 作业,它执行以下操作:从表 A 中读取记录 x。将记录 x + 1.000.000 写入表 A 中。这很有效,但在 310 条记录后失败。它显然与记录中的值无关。如果我将输
我正在使用iText将html转换为pdf,当我尝试注册fontProvider时,我得到EOFException,这里是相关代码: XMLWorkerFontProvider fontProvide
以下代码在反序列化期间抛出 EOFException [in line size = in.readInt();],我很困惑为什么会发生这种情况。 import java.io.IOException
我正在使用此代码读取 Java 中的文件 import java.io.*; public class IOReadDataStreams { public static void main(
我的目标是将远程服务器中的 200 个 .jpg 文件下载到我的 Android 手机(运行 jellybeans)。为了做到这一点,我在循环中运行下面的方法,并将不同的文件名分配给文件名参数。它运行
输出正确,但后面跟着一个 EOFException。我阅读了文档,但仍然不知道如何解决这个问题 try(ObjectInputStream ois = new ObjectInputStream(ne
我有一个通过套接字向主机发送数据的客户端。有时我会得到java.io.EOFException。 问题是:我如何知道是谁导致套接字关闭?由于远程主机关闭了套接字,该异常是否总是引发? 或者也可能是内部
这个问题已经有答案了: Java FileInputStream ObjectInputStream reaches end of file EOF (9 个回答) 已关闭 9 年前。 请看下面的代码
我尝试使用 this question's answer 来获得功能实现,但出现各种错误,现在出现 EOFException,并且在调试时,似乎文件未写入。 目标是从 URL 下载图像,将其保存到内部
我正在测试 ObjectInputStream 和 ObjectOutputStream 类 尝试在缓冲流对象中扭曲两者.. File file = new File("file.lel"); //A
我使用文件来缓冲它来显示流内容(因为它可能足够大以将其保存在 RAM 中)。我有两个线程:第一个线程从服务器下载文件并将其写入本地存储,第二个线程读取该文件并显示内容。 问题是,当第二个线程到达文件末
`INFO 11:44:29,874 Listening for thrift clients... ERROR 11:47:01,471 Exception in thread Thread[Rea
我在反序列化对象时遇到此异常: 控制台输出 sending request: GET_OBJS java.io.EOFException receiving response at java.io.O
我正在使用以下代码进行发布请求 public String executeHttpPost(String uri, String data) { HttpURLConnection conn
我正在通过加密的 ByteArrayOutputStream 将一个序列化和加密的对象写入数据库到一个大对象中。我可以检索这个大对象,但无法反序列化它。 这是我编写的代码: public void a
这个问题在这里已经有了答案: java.io.EOFException while writing and reading froma servlet (2 个答案) 关闭 10 年前。 当我尝试通
我正在尝试编写一个消息传递应用程序,并且我能够发送消息(显示为服务器客户端正确显示消息)但随后将我的客户端踢出服务器。服务器打印以下错误: java.io.EOFException at java.i
我有以下问题: 这段代码... try { fis = new FileInputStream(serializedKeyIndex); in = new Ob
我正在使用随机访问文件来编写一个使用 arrayList 存储的 raf。我不知道它是否可以完成,但我正在试一试,因为它是我创建此应用程序的最佳解决方案。 这是我遇到的运行时错误: Exception
我是一名优秀的程序员,十分优秀!