简体   繁体   中英

How can I handle long response in OkHttp Java?

I am attempting to use okhttp-3.12.0 and okio-1.9.0 in my JAVA project to make POST call to a web service.

I am able to successfully create the record, however, the web service returns a response of data type long which then throws a NoSuchMethodError because the OkHttp library tries to read it with readUtf8LineStrict.

Can someone with more experience advise me on how to work through this problem? Do I need to make changes to the underlying library or should I take a different approach?

  1. Make Post Call
Response response = client.newCall(request).execute();
                        System.out.println(response);
  1. Web Service Returns Response Body
{"recordId":"ABC123DEFZhC8O_KS8V2mkWPXreXpLHFZgSIyjH5Ue9Z4sUDe4ghkWsZcYlh55lrSTooSstxgMouuleKr0TqjYzuE2Xjz8OWBvxwAc8uLyJNm0TF1fUGwBz9_nrIgpsHcr-lwwQzOvxpCBwE-NV-NIym5ZLE5SgmO4jty0fUEld4kHt7yOL2_94-jTavICTwMsIaPfvXxx74Cox4R_lONNlmd2R8BSLhGHxLW-Hfh-fLZhOmPMF-2zmXQm2h3Poj-SI6PY_f7F2tLmEyR92JR33QFfVVOmRgJ5mC0U5adG_BXyKlREvlQIiwtvEQY3InIjlJZw0mpYAEY4VD7QmOPfGWYpwgUwqZELmVPIESrq2dT3LHIdfPLBQ**"}
  1. OkHttp Java library throws
Exception in thread "main" java.lang.NoSuchMethodError: 'java.lang.String okio.BufferedSource.readUtf8LineStrict(long)'

I was able to receive a long text response by updating the libraries I was using.

These two libraries are the most up to date versions I could work WITHOUT Kotlin.

  1. okhttp 3.12.0
  2. okio 1.17.5

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM