Get response body on 400 HTTP response in Android?

后端 未结 3 1495
攒了一身酷
攒了一身酷 2021-01-28 16:00

I\'m communicating with an API that I can not change that sends a 400 response when a request is not validated on the API side. It is a valid HTTP request, but the request data

3条回答
  •  野性不改
    2021-01-28 16:08

    Try that way:

    if (this.responseCode == HttpURLConnection.HTTP_OK) {
     inputStream = httpUrlConnection.getInputStream();
    } else {
    inputStream = httpUrlConnection.getErrorStream();
    }
    

提交回复
热议问题