I am writing a program that connects servlet to a I got the error: java.net.ProtocolException: the output can not be written after reading the input. If I check the URL in the comments with the code, but it works unfortunately without any complete work, I need to check the URL, so I think the problem HTTP protocol is based on a Request-response Pattern: You send your request first and the server returns once the server returns Vaar replied, so you can not send any more material, that does not mean it will not be. (How do the server know about a response code before you want to send it?) so when you call By looking at your code, you want to see that the connection itself was successful, but there is no need for it: if there is no connection, successful T, a HttpURLConnection , but I get trapped The URL was checked
Public zero connect (string method) throws exception {server = (HttpURLConnection) url.openConnection (); Server.setDoInput (true); Server.setDoOutput (true); Server.setUseCaches (wrong); Server.setRequestMethod (method); Server.setRequestProperty ("content-type", "app / XML"); Server.connect (); / * If (server.getResponseCode () == 200) {System.out.println ("The connection to the URL is OK:" + url); System.out.println ("------------------------------------------- ------- "); } Else System.out.println ("Connection Failed"); } * /
getResponseCode method but I do not know
server.getResponseCode () , You effectively tell the server that your request has been exhausted and it can be processed if you want to send more data, then you have to start a new request.
exception to
Server.connect () . But the result of the connection effort is not the same as the HTTP response code, which always comes after processing it by server on all your inputs.
Comments
Post a Comment