final OkHttpClient okHttpClient = new OkHttpClient.Builder()
.readTimeout(30, TimeUnit.SECONDS)
.connectTimeout(30, TimeUnit.SECONDS)
.addInterceptor(new GzipRequestInterceptor())
.build();
@Headers({
"Content-Type: application/json;charset=utf-8",
"Accept: application/json"
})
@Streaming
@POST("updateContent")
这是我用来从服务器获取压缩的Gzip响应的标头。
Gson gson = new GsonBuilder()
.setLenient()
.create();
Retrofit retrofit = new Retrofit.Builder()
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create(gson))
.baseUrl(BASE_URL)
.client(okHttpClient)
.build();
这是我正在使用的改造对象。
我收到此错误 “ JSON文档未完全使用”
但是如果我喜欢它,它会起作用:
ResponseHandler responseHandler = new BasicResponseHandler();
String response = (String) httpclient.execute(httpPost, responseHandler);
if (response != null && !"".equalsIgnoreCase(response)) {
String new_response = null;
byte[] zbytes = response.getBytes("ISO-8859-1");
// Add extra byte to array when Inflater is set to true
byte[] input = new byte[zbytes.length + 1];
System.arraycopy(zbytes, 0, input, 0, zbytes.length);
input[zbytes.length] = 0;
ByteArrayInputStream bin = new ByteArrayInputStream(input);
InflaterInputStream in = new InflaterInputStream(bin);
ByteArrayOutputStream bout = new ByteArrayOutputStream(1024);
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(bout);
IOUtils.copy(in, bufferedOutputStream);
in.close();
bufferedOutputStream.close();
new_response = bout.toString();
responseJsonData = new JSONObject(new_response);
但是我需要通过翻新来进行此操作,这会引发错误。在将改造用作自动改造中的gzip解压缩时,启用解析来自服务器的zip数据的功能。
com.google.gson.JsonSyntaxException:java.lang.IllegalStateException:预期为BEGIN_OBJECT,但位于第1行第1列的路径$