How to get string response from Retrofit2?

前端 未结 10 1499
时光取名叫无心
时光取名叫无心 2020-12-01 07:44

I am doing android, looking for a way to do a super basic http GET/POST request. I keep getting an error:

java.lang.IllegalArgumentException: Unable to creat         


        
10条回答
  •  失恋的感觉
    2020-12-01 08:08

    I take a look at Retrofit library and noticed that it parses response according to the type class inside Call. So you have two option: 1st: create a class according to the response from the server.

    2nd: get the response and handle it yourself (Not recommended Retrofit already handles it. So why do you use Retrofit as it is tailored for this job). Anyway instead of Call use Call and Call signin = service.jquery(); after this put the following

    call.enqueue(new Callback() {
      @Override
      public void onResponse(Response response, Retrofit retrofit) {
        // handle success
       String result = response.body().string();
    
      }
    
      @Override
      public void onFailure(Throwable t) {
        // handle failure
      }
    });
    

提交回复
热议问题