1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
BufferedReader inputFromUrl = null;
PrintWriter outputToUrl = null;
try {
URL externalUrl = new URL("http", "testUrl", 8080, "/applic.do");
URLConnection urlConnection = externalUrl.openConnection();
// inform the connection that we will send output and accept input
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);
urlConnection.setUseCaches(true);
urlConnection.setDefaultUseCaches(true);
urlConnection.setDefaultAllowUserInteraction(true);
urlConnection.setAllowUserInteraction(true);
outputToUrl = new PrintWriter(urlConnection.getOutputStream());
outputToUrl.println("testRead");
outputToUrl.flush();
outputToUrl.close();
inputFromUrl = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
String responsRequest = inputFromUrl.readLine();
} catch (Exception e) {
e.printStackTrace();
} |
Partager