gaglioppo
23-02-2006, 12:32
ciao amici,
ho un problema:
ho una form html del tipo:
<FORM METHOD=POST ENCTYPE="multipart/form-data" ACTION="http://............. NAME=........>
E-mail: <INPUT TYPE=TEXT NAME=email >
</form>
in un sito che sto analizzando.
Sto realizzandoun tool java per interrogare la form automaticamente.
il problema è che il sistema mi dice che: Badly formed E-mail Address
mentre se compilo la form a mano tutto funziona.
Sto usando il seguente pezzo di codice
File prediction =new File("nome");
File FileProperties = new File(prediction,"MODEL.properties");
FileWriter outFileProperties = new FileWriter(FileProperties);
PrintWriter FileP= new PrintWriter(outFileProperties) ;
FileP.println(http);
FileP.println(seq);
FileP.close();
String fileName = "MODEL.properties";
Properties props = new Properties();
FileInputStream in = new FileInputStream(fileName);
props.load(in);
URL url = new URL(props.getProperty("URL"));
props.remove("URL");
String r = doPost(url, props);
File outputFile = new File("MODEL.html");
FileWriter out2 = new FileWriter(outputFile);
PrintWriter out1= new PrintWriter(out2) ;
out1.println(r);
out1.close();
dove:
public static synchronized String doPost(URL url, Properties nameValuePairs)
throws IOException
{
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
PrintWriter out= new PrintWriter(connection.getOutputStream());
Enumeration enum2 = nameValuePairs.keys();
while (enum2.hasMoreElements()){
String name = (String)enum2.nextElement();
String value = nameValuePairs.getProperty(name);
char ch;
if (enum2.hasMoreElements()) ch = '&'; else ch = '\n';
out.print(name + "="
+ URLEncoder.encode(value,"UTF-8") + ch);
}
out.close();
BufferedReader in;
try{
in = new BufferedReader(new
InputStreamReader(connection.getInputStream()));
}
catch (FileNotFoundException exception){
InputStream err= ((HttpURLConnection)connection).getErrorStream();
if (err == null)
throw exception;
in = new BufferedReader(new InputStreamReader(err));
}
StringBuffer response = new StringBuffer();
String line;
while ((line = in.readLine()) != null)
response.append(line + "\n");
in.close();
return response.toString();
}//fine doPost
e ho creato un file MODEL.properties che contiene:
URL=http://www.qualcosa._submit.cgi
email=miamail@liberos.it'
dove sbagloio?
ho un problema:
ho una form html del tipo:
<FORM METHOD=POST ENCTYPE="multipart/form-data" ACTION="http://............. NAME=........>
E-mail: <INPUT TYPE=TEXT NAME=email >
</form>
in un sito che sto analizzando.
Sto realizzandoun tool java per interrogare la form automaticamente.
il problema è che il sistema mi dice che: Badly formed E-mail Address
mentre se compilo la form a mano tutto funziona.
Sto usando il seguente pezzo di codice
File prediction =new File("nome");
File FileProperties = new File(prediction,"MODEL.properties");
FileWriter outFileProperties = new FileWriter(FileProperties);
PrintWriter FileP= new PrintWriter(outFileProperties) ;
FileP.println(http);
FileP.println(seq);
FileP.close();
String fileName = "MODEL.properties";
Properties props = new Properties();
FileInputStream in = new FileInputStream(fileName);
props.load(in);
URL url = new URL(props.getProperty("URL"));
props.remove("URL");
String r = doPost(url, props);
File outputFile = new File("MODEL.html");
FileWriter out2 = new FileWriter(outputFile);
PrintWriter out1= new PrintWriter(out2) ;
out1.println(r);
out1.close();
dove:
public static synchronized String doPost(URL url, Properties nameValuePairs)
throws IOException
{
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
PrintWriter out= new PrintWriter(connection.getOutputStream());
Enumeration enum2 = nameValuePairs.keys();
while (enum2.hasMoreElements()){
String name = (String)enum2.nextElement();
String value = nameValuePairs.getProperty(name);
char ch;
if (enum2.hasMoreElements()) ch = '&'; else ch = '\n';
out.print(name + "="
+ URLEncoder.encode(value,"UTF-8") + ch);
}
out.close();
BufferedReader in;
try{
in = new BufferedReader(new
InputStreamReader(connection.getInputStream()));
}
catch (FileNotFoundException exception){
InputStream err= ((HttpURLConnection)connection).getErrorStream();
if (err == null)
throw exception;
in = new BufferedReader(new InputStreamReader(err));
}
StringBuffer response = new StringBuffer();
String line;
while ((line = in.readLine()) != null)
response.append(line + "\n");
in.close();
return response.toString();
}//fine doPost
e ho creato un file MODEL.properties che contiene:
URL=http://www.qualcosa._submit.cgi
email=miamail@liberos.it'
dove sbagloio?