Thanks for helping out Carl, its have been a great help, here comes the code that works. The program log�s in to a webserver, and with that cokie i go to a other plase and "GET" a telephone number, and there i get the HTML from that page back.
I don�t use POST anymore !
Frank Jacobsen
Frja@tdk.dk mport java.io.*;
import java.net.*;
import java.util.*;
public class SocketTest
{
public static void main(String[] args){
String ReturnBuffer = "";
String search_msisdn = "20100400" ;
try
{
System.setProperty("proxySet", "true");
System.setProperty("http.proxyHost", "192.168.190.31");
System.setProperty("http.proxyPort", "8080");
String urlName;
if (args.length > 0){
urlName = args[0];
}
else{
urlName = "http://someip/webapp/OCH2WebApp/index.jsp?userid=usetdc100&password=poluli&send=Login";
}
URL url = new URL(urlName);
HttpURLConnection connection =(HttpURLConnection) url.openConnection();
String cookie = connection.getHeaderField("Set-Cookie");
/*
if ( cookie != null ){
int idx = cookie.indexOf(";");
if ( idx >= 0 ){
cookie = cookie.substring(0, idx);
}
}
*/
/*
System.out.println("cookie=:" + cookie);
for (int i=0; ; i++){
String headerName = connection.getHeaderFieldKey(i);
String headerValue = connection.getHeaderField(i);
if ( headerName == null && headerValue == null ){
break;
}
if ( headerName == null ){
// The header value contains the server's HTTP version
}
System.out.println(headerName + "=:" + headerValue);
}
*/
connection =(HttpURLConnection) url.openConnection();
connection.setRequestProperty("Cookie", cookie);
// Simulate a communication:
try
{
BufferedReader in;
in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
}
catch(IOException e)
{
System.out.println("Exception ved get request: " + e);
}
urlName = "http://131.166.18.13/webapp/OCH2WebApp/telephonenumbercurrentstatus.jsp";
url = new URL(urlName);
connection =(HttpURLConnection) url.openConnection();
connection.setRequestProperty("Cookie", cookie);
// Simulate a communication:
try
{
BufferedReader in;
in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
}
catch(IOException e)
{
System.out.println("Exception ved get request: " + e);
}
// Do the search on the remote server:
urlName = "http://131.166.18.13/webapp/OCH2WebApp/telephonenumbercurrentstatus.jsp?telephoneNumberStart="
+ search_msisdn
+ "&Search=Search";
url = new URL(urlName);
connection =(HttpURLConnection) url.openConnection();
connection.setRequestProperty("Cookie", cookie);
//Receive the answer.
try
{
BufferedReader in;
in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
boolean more = true;
while (more)
{
char ch = (char) in.read() ;
ReturnBuffer += ch;
System.out.print(ch);
if(!in.ready()) more = false;
}
}
catch(IOException e)
{
System.out.println("Exceptionved send request: " + e);
}
connection.disconnect();
}
catch(Exception e)
{
System.out.println("Exception ved send request: " + e);
}
}
}