使用clojure Transit解析JSON时的java.io.EOFException

时间:2015-04-04 17:57:16

标签: json clojure transit

我正在使用(t/read request-body :json)从输入流中读取  我得到一个java.lang.RuntimeException: java.io.EOFException

{"A":"B", "C":"D"}
java.lang.RuntimeException: java.io.EOFException
                   ReaderFactory.java:122 com.cognitect.transit.impl.ReaderFactory$ReaderImpl.read
                  TransitFactory.java:136 com.cognitect.transit.TransitFactory$DeferredJsonReader.read
                          transit.clj:285 cognitect.transit/read

为什么会出现这种情况?

为了清楚起见,curl POST请求:

%curl -X POST ...../word -H "Content-Type: application/json" -d '{"A":"B", "C":"D"}' -v > abc.html 
* Hostname was NOT found in DNS cache
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:--     --:--:--     0*   Trying 178.63.65.149...
* Connected to ..... (178.63.65.149) port 80 (#0)
> POST /word HTTP/1.1
> User-Agent: curl/7.37.1
> Host: .....
> Accept: */*
> Content-Type: application/json
> Content-Length: 18
> 
} [data not shown]
* upload completely sent off: 18 out of 18 bytes
< HTTP/1.1 500 Server Error
* Server nginx/1.2.1 is not blacklisted
< Server: nginx/1.2.1
< Date: Sat, 04 Apr 2015 19:05:03 GMT
< Content-Type: text/html;charset=ISO-8859-1
< Content-Length: 13190
< Connection: keep-alive
< 
{ [data not shown]
100 13208  100 13190  100    18  79062    107 --:--:-- --:--:-- --:--:-- 79457
* Connection #0 to host ..... left intact

1 个答案:

答案 0 :(得分:1)

查看您的日志记录数据,您的请求正文实际上不是json,它看起来像是一个包含json文件上传的多部分/表单数据编码形式。