Hola indetectables, aqui estoy con mi pregunta y se que facil no es, como todo el mundo sabe estoy en medio de una Tool para compartir con mis Foros.
Tambien asi la hago y al mismo tiempo afianzo conocimientos de programación, bueno vamos al lio a ver si alguien ve lo que mis ojos no pueden ver hasta el momento.
Los parametros a pasar segun live http header son estos
Mostrar/Ocultar
[Enlace externo eliminado para invitados]
POST /up/upload.php HTTP/1.1
Host: host.com
User-Agent: Mozilla/5.0 (X11; Linux i686; rv:30.0) Gecko/20100101 Firefox/30.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: [Enlace externo eliminado para invitados]
Cookie: PHPSESSID=56f0e6cfbd5c66bb49b27a994535d5d7
Connection: keep-alive
Content-Type: multipart/form-data; boundary=---------------------------1035730252517518891493736084
Content-Length: 9767
-----------------------------1035730252517518891493736084
Content-Disposition: form-data; name="upload_range"
2
-----------------------------1035730252517518891493736084
Content-Disposition: form-data; name="upfile_0"; filename="shihtface.jpeg"
Content-Type: image/jpeg
ÿØÿà
El código que he hecho es este pero al parecer hago algo mal en los parametros post,
Mostrar/Ocultar
import java.io.*;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class FuckUrlMybrain {
public static void main(String []arg) throws MalformedURLException, IOException{
String archivoin="C:\\Documents and Settings\\Neutrox\\Escritorio\\Calico1.jpeg";
File fl = new File(archivoin);
FileInputStream fis = new FileInputStream(fl);
BufferedInputStream bis = new BufferedInputStream (fis);
String boundary= Long.toHexString(System.currentTimeMillis());
String post="--" + boundary+"\r\n"+"Content-Disposition: form-data; name=\"upload_range\""+"\r\n"+"\r\n"
+"2"+"\r\n"+"--" + boundary+"\r\n"
+"Content-Disposition: form-data; name=\"upfile_0\";filename=\""+fl.getName()+"\""
+"\r\n"+"Content-Type: application/x-msdownload"+"\r\n"+"\r\n";
String post1="--" + boundary+"\r\n"+"Content-Disposition: form-data; name=" + "\""
+ "upfile_1" + "\"" + ";" + "filename="
+ "\"" + "\"" + "\r\n"+ "\r\n"+
"--" + boundary + "\r\n" +
"Content-Disposition: form-data; name=" + "\"" + "submit" + "\"" + "\r\n" +
"Content-Type: application/octet-stream" + "\r\n"+ "\r\n"+
"--" + boundary + "--";
String conten="10508";
HttpURLConnection httpurlconnection=null;
URL url= new URL("[Enlace externo eliminado para invitados]");
httpurlconnection=(HttpURLConnection)url.openConnection();
httpurlconnection.setUseCaches(false);
httpurlconnection.setDoOutput(true);
httpurlconnection.setRequestMethod("POST");
httpurlconnection.setRequestProperty("Connection:"," keep-alive");
httpurlconnection.setRequestProperty("Content-Type: ","multipart/form-data; boundary="+boundary);
httpurlconnection.setRequestProperty("Content-Length:",conten);
DataOutputStream das= new DataOutputStream(httpurlconnection.getOutputStream());
das.write(post.getBytes());
try {
int c;
byte buffer1[]=new byte [4056];
while((c=bis.read(buffer1))>0)
das.write(buffer1, 0, c);
}
catch (Exception cony){
cony.printStackTrace();}
finally{
bis.close();
}
das.write(post1.getBytes());
das.flush();
das.close();
try{
Charset charset = Charset.forName("utf-8");
BufferedReader br = new BufferedReader(new InputStreamReader(httpurlconnection.getInputStream(), charset));
String line = br.readLine();
StringBuffer response = new StringBuffer();
while (line != null) {
response = response.append(line);
line = br.readLine();
System.out.println(line);
}
String pattern = "\\[url\\=(.+?)\\]\\[img\\](.*?)\\[\\/img\\]\\[\\/url\\]";
Pattern p = Pattern.compile(pattern);
Matcher m = p.matcher(response.toString());
if (m.find()){
System.out.println(m.group(0));
System.out.println(m.group(1));
System.out.println(m.group(2));
}
else {
System.out.println("Matchers not found");
}
}catch(Exception inpt){inpt.printStackTrace();
}
finally{
}
}
}
Aqui el error que me retorna java
Mostrar/Ocultar
run:
java.io.IOException: Server returned HTTP response code: 400 for URL: http:/host.com/up/upload.php
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1626)
at FuckUrlMybrain.main(FuckUrlMybrain.java:57)
BUILD SUCCESSFUL (total time: 3 seconds)
Cabe decir que nunca habia trabajado con el protocolo http anteriormente y en estas practicas para haceros la Tool he aprendido mucho, sobre el protocolo http, sobre la generación de Regex, en fin estoy disfrutando pero al mismo tiempo estoy hechando el higado por la boca, con algunos tropezones.
Espero que me ayudeis y al mismo tiempo aprender haciendos la Tool , pues en este mundo nunca dejas de aprender