FileNotFoundException while getting the InputStream object from HttpURLConnection

前端 未结 7 2161
清酒与你
清酒与你 2020-11-29 02:47

I am trying to send a post request to a url using HttpURLConnection (for using cUrl in java). The content of the request is xml and at the end point, the application proces

7条回答
  •  伪装坚强ぢ
    2020-11-29 02:58

    To anyone with this problem in the future, the reason is because the status code was a 404 (or in my case was a 500). It appears the InpuStream function will throw an error when the status code is not 200.

    In my case I control my own server and was returning a 500 status code to indicate an error occurred. Despite me also sending a body with a string message detailing the error, the inputstream threw an error regardless of the body being completely readable.

    If you control your server I suppose this can be handled by sending yourself a 200 status code and then handling whatever the string error response was.

提交回复
热议问题