Faire mumuse sur les URL : pas d'idées
Bonjour,
Je suis en train de réaliser une clasee qui va tester un site (en gros elle va faire ce qu'une personne fait derrière sont PC), donc voici ma classe
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| package org.skyrecon.skyline.emulation.main;
import java.io.IOException;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
import org.skyrecon.skyline.emulation.util.HttpResponse;
public class VirtualUser
{
private static HttpClient client = null; // unique emulation client instance
private static PostMethod auth = null;
private HttpClient http; // the HTTP transporter (unique)
private String script2connect = "" ;
private String website;
/** Create the virtual client
* Virtual client are not personas, all virtual clients are doing the same thing
* @param login
* @param password
* @throws IOException
*/
public VirtualUser() throws IOException
{
// set log4j property
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
this.website = "http://localhost/skyline/";
this.script2connect = "script/login.php";
this.http = VirtualUser.getClient();
System.out.println("Step 0 : Client emulation");
}
private static HttpClient getClient()
{
if(VirtualUser.client == null)
{
VirtualUser.client = new HttpClient();
}
return VirtualUser.client;
}
private static PostMethod getStep(String url)
{
if(VirtualUser.auth == null)
{
VirtualUser.auth = new PostMethod(url);
}
return VirtualUser.auth;
}
public void connect(String login, String password) throws HttpException, IOException
{
PostMethod method = VirtualUser.getStep(this.website+this.script2connect);
System.out.println("Step 1 : Connection of user "+login);
NameValuePair[] data = {
new NameValuePair("login", login),
new NameValuePair("passwd", password)
};
method.setRequestBody(data);
method.setRequestHeader("Content-type","application/x-www-form-urlencoded"); // to submit the form
int responseCode = this.http.executeMethod(method);
String responseBody = method.getResponseBodyAsString();
if(responseCode==302)
{
String newURL = this.website.concat(HttpResponse.getHeader(method,"location"));
System.out.println("NOTICE :: Redirection to "+newURL);
System.out.println(this.website+newURL);
}
else if(responseBody.equals(""))
{
System.out.println("Error : HTTP code "+responseCode);
}
}
} |
le problème que j'ai c'est que newURL vaut
Code:
http://localhost/skyline/http://localhost/skyline/ ../panel.php
et he vois pas comment arriver à mes fins, c'est-à-dire avoir
Code:
http://localhost/skyline/http://localhost/skyline/panel.php
je ne sais pas comment enlevé cette espace ni les points, et j'ai regardé du coté de la classe URL, et je ne vois pa ce qui pourrait correspondre à mes besoins.
auriez vous des idées ?