zeltron a écrit a écrit :
Je suis d'accord avec ca mais pour renvoyer le cookie au server il faut que tu utilises le header "Cookie" et non pas "Set-Cookie" (le header Set-Cookie ne peut être envoyé que par un server).
|
oui, tu as raison, je ne lai pas precise, mais jai tenu compte de cette remarque par la suite, jai modifié cela,...ca ne marche toujours pas, voici mon nouveau code:
public void test() {
HttpURLConnection connection = null;
PrintWriter out = null;
BufferedReader in = null;
String response = null, line = null;
String boundary=new String("--------------boundary--------------" );
String streamsend=new String("--"+boundary+"\r\n" );
try {
URL url = new URL(URL);
connection= (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST" );
connection.setRequestProperty("Content-Type", "text/plain" );
connection.setRequestProperty("Cookie", "sesessionid=LOU3LVAAAAACPLAQABYR5MY;Path=/" );
connection.setRequestProperty("Connection", "Keep-Alive" );
out = new PrintWriter(connection.getOutputStream());
response = "";
streamsend+="Content-Type: text/plain";
streamsend+="\r\n";
streamsend+="contenu document\r\n";
streamsend+="--"+boundary+"\r\n";
out.print(streamsend);
////////////////////////////////////////////////////
//affichage //
////////////////////////////////////////////////////
for (int k = 0; connection.getHeaderField(k) != null; k++) {
if (connection.getHeaderFieldKey(k) != null)response += "\"" +connection.getHeaderFieldKey(k) + ":\"";
response += connection.getHeaderField(k);
response += "\n";
System.out.println(k);
}
line = "";
in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
while ((line = in.readLine()) != null) {
response += line;
}
in.close();
out.close();
}
catch (Exception e) {
e.printStackTrace();
connection.disconnect();
}
System.out.println(response+"\n"+streamsend);
}
et le resultat:
HTTP/1.1 200 ok
"Date:"Tue, 20 Mar 2001 11:33:16 GMT
"Server:"IBM_HTTP_Server/1.3.6.2 Apache/1.3.7-dev (Win32)
"Connection:"close
"Content-Type:"text/html
=>on dirait quil ne tient absolument pas compte de setproperty...