FileNotFoundException while getting the InputStream object from HttpURLConnection

前端 未结 7 2089
清酒与你
清酒与你 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 03:22

    I don't know about your Spring/JAXB combination, but the average REST webservice won't return a response body on POST/PUT, just a response status. You'd like to determine it instead of the body.

    Replace

    InputStream response = con.getInputStream();
    

    by

    int status = con.getResponseCode();
    

    All available status codes and their meaning are available in the HTTP spec, as linked before. The webservice itself should also come along with some documentation which overviews all status codes supported by the webservice and their special meaning, if any.

    If the status starts with 4nn or 5nn, you'd like to use getErrorStream() instead to read the response body which may contain the error details.

    InputStream error = con.getErrorStream();
    
    0 讨论(0)
提交回复
热议问题