[Solved] Sending an integer in http PUT request in java


You are trying to create a Reader for the response for your URL call, but likely the socket has already been closed. You should check your httpConnection.getXXXStream calls to make sure the httpConnection is still alive and the return value from the getStream calls is not null.

— edit —

Your check for responseCode != 200 is a problem. None of the response codes in the 100s and 200s are errors, and will not use the error stream. Otherwise, you should check that the inputstreams you are getting from the httpConnection, like

    if(httpConnection.getResponseCode() !=200){
        String error_resp;
        InputStream in = httpConnection.getErrorStream();
        if (in == null) return; // check if the error stream is null
       BufferedReader error_responseBuffer = new BufferedReader(new InputStreamReader(
            (httpConnection.getErrorStream()))); 
       while((error_resp = error_responseBuffer.readLine()) != null){
           System.out.println("Error responsecode => "+httpConnection.getResponseCode()+"error => "+error_resp);
           output = new JSONObject(error_resp);
       }
    }else {
        InputStream in = httpConnection.getInputStream();
        if (in == null) return; // check inputstream
        BufferedReader responseBuffer = new BufferedReader(new InputStreamReader(
                (in)));
        String httpresponse;
        StringBuilder content = new StringBuilder();
        while((httpresponse = responseBuffer.readLine()) != null){
            content.append(httpresponse);
        }
         output = new JSONObject(content.toString());
    }
    httpConnection.disconnect();

1

solved Sending an integer in http PUT request in java