/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package neembuu.uploader.test.plugins; import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.mime.HttpMultipartMode; import org.apache.http.entity.mime.MultipartEntity; import org.apache.http.entity.mime.content.ContentBody; import org.apache.http.entity.mime.content.FileBody; import org.apache.http.entity.mime.content.StringBody; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.util.EntityUtils; /** * * @author Dinesh */ public class ZippyShareUploaderPlugin { private static URL u; private static HttpURLConnection uc; private static BufferedReader br; private static String tmp; private static String zippylink; private static String postURL = ""; private static File file; private static String uploadresponse = ""; private static String downloadlink=""; public static void main(String[] args) throws Exception { initialize(); postURL = "http://" + zippylink + ".zippyshare.com/upload"; fileUpload(); } private static void initialize() throws IOException, Exception { System.out.println("Getting zippyshare dynamic upload link"); u = new URL("http://www.zippyshare.com/"); uc = (HttpURLConnection) u.openConnection(); br = new BufferedReader(new InputStreamReader(u.openStream())); String k = ""; while ((tmp = br.readLine()) != null) { k += tmp; } zippylink = parseResponse(k, "var server = '", "'"); zippylink = zippylink.toLowerCase(); System.out.println(zippylink); } public static String parseResponse(String response, String stringStart, String stringEnd) { response = response.substring(response.indexOf(stringStart)); response = response.replace(stringStart, ""); response = response.substring(0, response.indexOf(stringEnd)); return response; } private static void fileUpload() throws IOException { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(postURL); //httppost.setHeader("Cookie", sidcookie+";"+mysessioncookie); file = new File("h:/UploadingdotcomUploaderPlugin.java"); MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); ContentBody cbFile = new FileBody(file); mpEntity.addPart("Filename", new StringBody(file.getName())); mpEntity.addPart("notprivate", new StringBody("false")); mpEntity.addPart("folder", new StringBody("/")); mpEntity.addPart("Filedata", cbFile); httppost.setEntity(mpEntity); System.out.println("executing request " + httppost.getRequestLine()); System.out.println("Now uploading your file into zippyshare.com"); HttpResponse response = httpclient.execute(httppost); HttpEntity resEntity = response.getEntity(); System.out.println(response.getStatusLine()); if (resEntity != null) { uploadresponse = EntityUtils.toString(resEntity); } downloadlink=parseResponse(uploadresponse, "value=\"http://", "\""); downloadlink="http://"+downloadlink; System.out.println("Download Link : "+downloadlink); httpclient.getConnectionManager().shutdown(); } }