我正在使用改装(1.9版)和杰克逊(杰克逊转换器1.9版)。我们有 API,它经常以原始字符串的形式发送响应。
我们的 api 客户端如下:
RestAdapter.Builder builder = new RestAdapter.Builder()
.setEndpoint(API_URL)
.setClient(new OkClient(new OkHttpClient()))
.setConverter(new JacksonConverter())
以下是基本要求:
api.basicPostRequest(Sample object, new Callback<String>() {
@Override
public void success(String s, Response response) {
})
@Override
public void failure(RetrofitError error) {
}
以下是我们得到的 http 响应:
<--- HTTP 200 https://sample url (606ms)
Date: Fri, 22 Apr 2016 13:57:46 GMT
Server: Apache
X-Powered-By: PleskLin
Connection: close
Transfer-Encoding: chunked
Content-Type: text/plain
OkHttp-Selected-Protocol: http/1.1
OkHttp-Sent-Millis: 1461331000541
OkHttp-Received-Millis: 1461331001011
OK
但是,执行在public void failure(RetrofitError error)
中继续,改造会给出此错误:
ERROR: retrofit.RetrofitError: com.fasterxml.jackson.core.JsonParseException:
Unrecognized token 'OK': was expecting ('true', 'false' or 'null')
at [Source: retrofit.
ExceptionCatchingTypedInput$ExceptionCatchingInputStream@5290df1c; line: 1, column: 5]
这是错误还是我做错了什么或错过了什么?
关于
使用 Retrofit 1.x,如果您需要这样的东西,方法是让您的请求返回 retrofit.client.Response
,然后通过位于 Response.getBody().in()
中的流自己获取正文内容。