下面列出了org.apache.http.entity.mime.MultipartEntity#addPart ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Test
@Ignore("UT3 - P3")
public void testMultiPartRequestToLarge() throws IOException {
TestHttpClient client = new TestHttpClient();
try {
String uri = DefaultServer.getDefaultServerURL() + "/servletContext/2";
HttpPost post = new HttpPost(uri);
MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
entity.addPart("formValue", new StringBody("myValue", "text/plain", StandardCharsets.UTF_8));
entity.addPart("file", new FileBody(new File(MultiPartTestCase.class.getResource("uploadfile.txt").getFile())));
post.setEntity(entity);
HttpResponse result = client.execute(post);
final String response = HttpClientUtils.readResponse(result);
Assert.assertEquals("EXCEPTION: class java.lang.IllegalStateException", response);
} catch (IOException expected) {
//in some environments the forced close of the read side will cause a connection reset
} finally {
client.getConnectionManager().shutdown();
}
}
@Test
public void testFileUploadWithEagerParsingAndNonASCIIFilename() throws Exception {
DefaultServer.setRootHandler(new EagerFormParsingHandler().setNext(createHandler()));
TestHttpClient client = new TestHttpClient();
try {
HttpPost post = new HttpPost(DefaultServer.getDefaultServerURL() + "/path");
MultipartEntity entity = new MultipartEntity();
entity.addPart("formValue", new StringBody("myValue", "text/plain", StandardCharsets.UTF_8));
File uploadfile = new File(MultipartFormDataParserTestCase.class.getResource("uploadfile.txt").getFile());
FormBodyPart filePart = new FormBodyPart("file", new FileBody(uploadfile, "τεστ", "application/octet-stream", Charsets.UTF_8.toString()));
filePart.addField("Content-Disposition", "form-data; name=\"file\"; filename*=\"utf-8''%CF%84%CE%B5%CF%83%CF%84.txt\"");
entity.addPart(filePart);
post.setEntity(entity);
HttpResponse result = client.execute(post);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
HttpClientUtils.readResponse(result);
} finally {
client.getConnectionManager().shutdown();
}
}
@Override
protected String login(ApplicationContext currentContext) throws CLIException {
File credentials = new File(pathname);
if (!credentials.exists()) {
throw new CLIException(REASON_INVALID_ARGUMENTS,
String.format("File does not exist: %s", credentials.getAbsolutePath()));
}
if (warn) {
writeLine(currentContext, "Using the default credentials file: %s", credentials.getAbsolutePath());
}
HttpPost request = new HttpPost(currentContext.getResourceUrl("login"));
MultipartEntity entity = new MultipartEntity();
entity.addPart("credential",
new ByteArrayBody(FileUtility.byteArray(credentials), APPLICATION_OCTET_STREAM.getMimeType()));
request.setEntity(entity);
HttpResponseWrapper response = execute(request, currentContext);
if (statusCode(OK) == statusCode(response)) {
return StringUtility.responseAsString(response).trim();
} else {
handleError("An error occurred while logging: ", response, currentContext);
throw new CLIException(REASON_OTHER, "An error occurred while logging.");
}
}
public static void fileUpload() throws IOException {
HttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
file = new File("/home/vigneshwaran/dinesh.txt");
HttpPost httppost = new HttpPost(postURL);
httppost.setHeader("Cookie", langcookie + ";" + sessioncookie + ";" + mailcookie + ";" + namecookie + ";" + rolecookie + ";" + orderbycookie + ";" + directioncookie + ";");
MultipartEntity mpEntity = new MultipartEntity();
ContentBody cbFile = new FileBody(file);
mpEntity.addPart("files[]", cbFile);
httppost.setEntity(mpEntity);
System.out.println("Now uploading your file into wupload...........................");
HttpResponse response = httpclient.execute(httppost);
HttpEntity resEntity = response.getEntity();
System.out.println(response.getStatusLine());
if (response.getStatusLine().getStatusCode() == 302
&& response.getFirstHeader("Location").getValue().contains("upload/done/")) {
System.out.println("Upload successful :)");
} else {
System.out.println("Upload failed :(");
}
}
private static void fileUpload() throws Exception {
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(postURL);
// if (login) {
// httppost.setHeader("Cookie", cookies.toString());
// }
// httppost.setHeader("Content-Type", "multipart/form-data");
// httppost.setHeader("Host", "upload.crocko.com");
// httppost.setHeader("User-Agent", "Shockwave Flash");
file = new File("C:\\Documents and Settings\\dinesh\\Desktop\\MegaUploadUploaderPlugin.java");
MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
ContentBody cbFile = new FileBody(file);
mpEntity.addPart("Filename", new StringBody(file.getName()));
if (login) {
System.out.println("adding php sess .............");
mpEntity.addPart("PHPSESSID", new StringBody(sessionid));
}
mpEntity.addPart("Filedata", cbFile);
httppost.setEntity(mpEntity);
System.out.println("executing request " + httppost.getRequestLine());
System.out.println("Now uploading your file into crocko");
HttpResponse response = httpclient.execute(httppost);
HttpEntity resEntity = response.getEntity();
System.out.println(response.getStatusLine());
if (resEntity != null) {
uploadresponse = EntityUtils.toString(resEntity);
}
//
System.out.println("Upload response : " + uploadresponse);
downloadlink = parseResponse(uploadresponse, "Download link:", "</dd>");
downloadlink = parseResponse(downloadlink, "value=\"", "\"");
deletelink = parseResponse(uploadresponse, "Delete link:", "</a></dd>");
deletelink = deletelink.substring(deletelink.indexOf("http://"));
System.out.println("Download link : " + downloadlink);
System.out.println("Delete link : " + deletelink);
}
private void fileUpload() throws Exception {
HttpClient httpclient = new DefaultHttpClient();
if (badongoAccount.loginsuccessful) {
postURL = "http://upload.badongo.com/mpu_upload.php";
}
HttpPost httppost = new HttpPost(postURL);
MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
mpEntity.addPart("Filename", new StringBody(file.getName()));
if (badongoAccount.loginsuccessful) {
mpEntity.addPart("PHPSESSID", new StringBody(dataid));
}
mpEntity.addPart("Filedata", createMonitoredFileBody());
httppost.setEntity(mpEntity);
NULogger.getLogger().log(Level.INFO, "executing request {0}", httppost.getRequestLine());
NULogger.getLogger().info("Now uploading your file into badongo.com");
uploading();
HttpResponse response = httpclient.execute(httppost);
HttpEntity resEntity = response.getEntity();
// uploadresponse = response.getLastHeader("Location").getValue();
//NULogger.getLogger().log(Level.INFO, "Upload response : {0}", uploadresponse);
NULogger.getLogger().info(response.getStatusLine().toString());
if (resEntity != null) {
uploadresponse = EntityUtils.toString(resEntity);
}
// if (resEntity != null) {
// resEntity.consumeContent();
// }
NULogger.getLogger().log(Level.INFO, "res {0}", uploadresponse);
httpclient.getConnectionManager().shutdown();
}
public void fileUpload() throws Exception {
httpPost = new NUHttpPost(postURL);
MultipartEntity mpEntity = new MultipartEntity();
mpEntity.addPart("sub", new StringBody("upload"));
mpEntity.addPart("cookie", new StringBody(RapidShareAccount.getRscookie()));
mpEntity.addPart("folder", new StringBody("0"));
mpEntity.addPart("filecontent", createMonitoredFileBody());
httpPost.setEntity(mpEntity);
uploading();
NULogger.getLogger().info("Now uploading your file into rs...........................");
httpResponse = httpclient.execute(httpPost, httpContext);
HttpEntity resEntity = httpResponse.getEntity();
NULogger.getLogger().info(httpResponse.getStatusLine().toString());
if (resEntity != null) {
gettingLink();
uploadresponse = EntityUtils.toString(resEntity);
NULogger.getLogger().log(Level.INFO, "Actual response : {0}", uploadresponse);
uploadresponse = uploadresponse.replace("COMPLETE\n", "");
// downloadid=uploadresponse.substring(uploadresponse.indexOf("E")+1);
downloadid = uploadresponse.substring(0, uploadresponse.indexOf(","));
uploadresponse = uploadresponse.replace(downloadid + ",", "");
filename = uploadresponse.substring(0, uploadresponse.indexOf(","));
NULogger.getLogger().log(Level.INFO, "download id : {0}", downloadid);
// filename=uploadresponse.substring(uploadresponse.indexOf(","));
// filename=uploadresponse.substring(0, uploadresponse.indexOf(","));
NULogger.getLogger().log(Level.INFO, "File name : {0}", filename);
downloadlink = "http://rapidshare.com/files/" + downloadid + "/" + filename;
NULogger.getLogger().log(Level.INFO, "Download Link :{0}", downloadlink);
downURL = downloadlink;
uploadFinished();
}
}
/**
* Create Post Request with FormBodyPart body
*/
public HttpPost createPost(String uri, LinkedList<FormBodyPart> partsList) {
HttpPost postRequest = new HttpPost(uri);
MultipartEntity multipartRequest = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
for (FormBodyPart part : partsList) {
multipartRequest.addPart(part);
}
postRequest.setEntity(multipartRequest);
return postRequest;
}
public static void fileUpload() throws IOException {
HttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
file = new File("H:\\c programs.doc");
filelength = file.length();
if (!username.isEmpty() && !password.isEmpty()) {
postURL = megauploadlink + "upload_done.php?UPLOAD_IDENTIFIER=" + uploadID + "&user=undefined&s=" + filelength;
} else {
postURL = megauploadlink + "upload_done.php?UPLOAD_IDENTIFIER=" + uploadID + "&" + usercookie + "&s=" + filelength;
}
HttpPost httppost = new HttpPost(postURL);
httppost.setHeader("Cookie", usercookie);
MultipartEntity mpEntity = new MultipartEntity();
ContentBody cbFile = new FileBody(file);
mpEntity.addPart("", cbFile);
httppost.setEntity(mpEntity);
System.out.println("Now uploading your file into megaupload...........................");
HttpResponse response = httpclient.execute(httppost);
HttpEntity resEntity = response.getEntity();
System.out.println(response.getStatusLine());
if (resEntity != null) {
downloadlink = EntityUtils.toString(resEntity);
}
}
@Override
public void run() {
try {
if (turboBitAccount.loginsuccessful) {
httpContext = turboBitAccount.getHttpContext();
responseString = NUHttpClientUtils.getData("http://turbobit.net/", httpContext);
doc = Jsoup.parse(responseString);
userId = doc.select("div.html-upload-form form input:eq(1)").val();
maxFileSizeLimit = 107374182400l; //100 GB
} else {
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
maxFileSizeLimit = 209715200l; //200 MB
}
if (file.length() > maxFileSizeLimit) {
throw new NUMaxFileSizeException(maxFileSizeLimit, file.getName(), turboBitAccount.getHOSTNAME());
}
uploadInitialising();
initialize();
httpPost = new NUHttpPost(uploadURL);
MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
mpEntity.addPart("apptype", new StringBody("fd1"));
mpEntity.addPart("Filedata", createMonitoredFileBody());
if(turboBitAccount.loginsuccessful){
mpEntity.addPart("user_id", new StringBody(userId));
mpEntity.addPart("folder_id", new StringBody("0"));
}
httpPost.setEntity(mpEntity);
NULogger.getLogger().log(Level.INFO, "executing request {0}", httpPost.getRequestLine());
NULogger.getLogger().info("Now uploading your file into TurboBit.net");
uploading();
httpResponse = httpclient.execute(httpPost, httpContext);
responseString = EntityUtils.toString(httpResponse.getEntity());
//Read the links
gettingLink();
NULogger.getLogger().log(Level.INFO, "responseString : {0}", responseString);
JSONObject jSonObject = new JSONObject(responseString);
if(jSonObject.has("result") && jSonObject.getBoolean("result")){
String fileId = jSonObject.getString("id");
// http://turbobit.net/o99r7k248hdv/Directory.Lister.1.68_SoftArchive.net.rar.html
downloadlink = "http://turbobit.net/" +fileId+ "/" + file.getName() + ".html";
NULogger.getLogger().log(Level.INFO, "Download link : {0}", downloadlink);
downURL = downloadlink;
uploadFinished();
}
else{
throw new Exception("There isn't a result or it's false.");
}
} catch(NUException ex){
ex.printError();
uploadInvalid();
} catch (Exception e) {
NULogger.getLogger().log(Level.SEVERE, "TurboBit.net exception: {0}", e);
uploadFailed();
}
}
@Override
public void run() {
try {
if (safeSharingAccount.loginsuccessful) {
userType = "reg";
httpContext = safeSharingAccount.getHttpContext();
} else {
userType = "anon";
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
}
if(safeSharingAccount.isPremium()){
userType = "prem";
maxFileSizeLimit = 4194304000L; // 4,000 MB
}
else{
maxFileSizeLimit = 52428800; // 50 MB
}
if (file.length() > maxFileSizeLimit) {
throw new NUMaxFileSizeException(maxFileSizeLimit, file.getName(), host);
}
uploadInitialising();
initialize();
long uploadID;
Random random = new Random();
uploadID = Math.round(random.nextFloat() * Math.pow(10,12));
uploadid_s = String.valueOf(uploadID);
uploadURL += uploadid_s + "&js_on=1&utype=" + userType + "&upload_type=file";
// http://37.187.161.87/cgi-bin/upload.cgi?upload_id=096036646684&js_on=1&utype=reg&upload_type=file
httpPost = new NUHttpPost(uploadURL);
MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
mpEntity.addPart("upload_type", new StringBody("file"));
mpEntity.addPart("sess_id", new StringBody(sessionID));
mpEntity.addPart("srv_tmp_url", new StringBody(srv_tmp_url));
mpEntity.addPart("m_e", new StringBody(m_e));
mpEntity.addPart("file_0", createMonitoredFileBody());
mpEntity.addPart("file_0_descr", new StringBody("Uploaded via NeembuuUploader"));
mpEntity.addPart("submit_btn", new StringBody("Start Upload"));
httpPost.setEntity(mpEntity);
NULogger.getLogger().log(Level.INFO, "executing request {0}", httpPost.getRequestLine());
NULogger.getLogger().info("Now uploading your file into SafeSharing.eu");
uploading();
httpResponse = httpclient.execute(httpPost, httpContext);
responseString = EntityUtils.toString(httpResponse.getEntity());
doc = Jsoup.parse(responseString);
//Read the links
gettingLink();
upload_fn = doc.select("textarea[name=fn]").val();
if (upload_fn != null) {
httpPost = new NUHttpPost("http://safesharing.eu");
List<NameValuePair> formparams = new ArrayList<NameValuePair>();
formparams.add(new BasicNameValuePair("fn", upload_fn));
formparams.add(new BasicNameValuePair("op", "upload_result"));
formparams.add(new BasicNameValuePair("st", "OK"));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");
httpPost.setEntity(entity);
httpResponse = httpclient.execute(httpPost, httpContext);
responseString = EntityUtils.toString(httpResponse.getEntity());
doc = Jsoup.parse(responseString);
downloadlink = doc.select("textarea").eq(0).val();
deletelink = doc.select("textarea").eq(4).val();
NULogger.getLogger().log(Level.INFO, "Delete link : {0}", deletelink);
NULogger.getLogger().log(Level.INFO, "Download link : {0}", downloadlink);
downURL = downloadlink;
delURL = deletelink;
uploadFinished();
}
} catch(NUException ex){
ex.printError();
uploadInvalid();
} catch (Exception e) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, e);
uploadFailed();
}
}
@Override
public void run() {
try {
if (vShareAccount.loginsuccessful) {
userType = "reg";
httpContext = vShareAccount.getHttpContext();
sessionID = CookieUtils.getCookieValue(httpContext, "xfss");
maxFileSizeLimit = 3196059648L; // 3,048 MB
} else {
userType = "anon";
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
maxFileSizeLimit = 2122317824L; // 2,024 MB
}
addExtensions();
//Check extension
if(!FileUtils.checkFileExtension(allowedVideoExtensions, file)){
throw new NUFileExtensionException(file.getName(), host);
}
if (file.length() > maxFileSizeLimit) {
throw new NUMaxFileSizeException(maxFileSizeLimit, file.getName(), host);
}
uploadInitialising();
initialize();
long uploadID;
Random random = new Random();
uploadID = Math.round(random.nextFloat() * Math.pow(10,12));
uploadid_s = String.valueOf(uploadID);
sess_id = StringUtils.stringBetweenTwoStrings(responseString, "name=\"sess_id\" value=\"", "\"");
srv_tmp_url = uploadURL;
uploadURL = StringUtils.removeLastChars(uploadURL, 3) + "cgi-bin/upload.cgi?upload_id=" + uploadid_s + "&js_on=1&utype=" + userType + "&upload_type=file";
httpPost = new NUHttpPost(uploadURL);
MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
mpEntity.addPart("js_on", new StringBody("1"));
mpEntity.addPart("upload_id", new StringBody(uploadid_s));
mpEntity.addPart("upload_type", new StringBody("file"));
mpEntity.addPart("utype", new StringBody(userType));
mpEntity.addPart("sess_id", new StringBody(sess_id));
mpEntity.addPart("srv_tmp_url", new StringBody(srv_tmp_url));
mpEntity.addPart("file_0_descr", new StringBody(""));
mpEntity.addPart("file_0_public", new StringBody("1"));
mpEntity.addPart("file_0", createMonitoredFileBody());
mpEntity.addPart("submit_btn", new StringBody("Done"));
mpEntity.addPart("tos", new StringBody("1"));
httpPost.setEntity(mpEntity);
NULogger.getLogger().log(Level.INFO, "executing request {0}", httpPost.getRequestLine());
NULogger.getLogger().info("Now uploading your file into VShare.eu");
uploading();
httpResponse = httpclient.execute(httpPost, httpContext);
responseString = EntityUtils.toString(httpResponse.getEntity());
doc = Jsoup.parse(responseString);
//Read the links
gettingLink();
upload_fn = doc.select("textarea[name=fn]").val();
if (upload_fn != null) {
httpPost = new NUHttpPost("http://vshare.eu/");
List<NameValuePair> formparams = new ArrayList<NameValuePair>();
formparams.add(new BasicNameValuePair("fn", upload_fn));
formparams.add(new BasicNameValuePair("op", "upload_result"));
formparams.add(new BasicNameValuePair("st", "OK"));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");
httpPost.setEntity(entity);
httpResponse = httpclient.execute(httpPost, httpContext);
responseString = EntityUtils.toString(httpResponse.getEntity());
doc = Jsoup.parse(responseString);
downloadlink = doc.select("textarea").first().val();
deletelink = doc.select("textarea").eq(2).val();
NULogger.getLogger().log(Level.INFO, "Delete link : {0}", deletelink);
NULogger.getLogger().log(Level.INFO, "Download link : {0}", downloadlink);
downURL = downloadlink;
delURL = deletelink;
uploadFinished();
}
} catch(NUException ex){
ex.printError();
uploadInvalid();
} catch (Exception e) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, e);
uploadFailed();
}
}
@Override
public void run() {
try {
if (sharedAccount.loginsuccessful) {
userType = "reg";
httpContext = sharedAccount.getHttpContext();
//sessionID = CookieUtils.getCookieValue(httpContext, "xfss");
maxFileSizeLimit = 1073741824L; // 1 GB
}
else {
host = "Shared.com";
uploadInvalid();
return;
}
if (file.length() > maxFileSizeLimit) {
throw new NUMaxFileSizeException(maxFileSizeLimit, file.getName(), host);
}
uploadInitialising();
initialize();
httpPost = new NUHttpPost("http://shared.com/upload/process");
httpPost.setHeader("Host", "shared.com");
httpPost.setHeader("Referer", sharedAccount.member_upload_url);
httpPost.setHeader("Accept", "application/json, text/javascript, */*;");
httpPost.setHeader("X-CSRF-TOKEN", authenticity_token);
httpPost.setHeader("X-Requested-With", "XMLHttpRequest");
MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
mpEntity.addPart("files[]", createMonitoredFileBody());
httpPost.setEntity(mpEntity);
NULogger.getLogger().log(Level.INFO, "executing request {0}", httpPost.getRequestLine());
NULogger.getLogger().info("Now uploading your file into Shared.com");
uploading();
httpResponse = httpclient.execute(httpPost, httpContext);
responseString = EntityUtils.toString(httpResponse.getEntity());
if (responseString.isEmpty()){
uploadFailed();
}
//Read the links
gettingLink();
downloadlink = StringUtils.stringBetweenTwoStrings(responseString, "\"url\":\"", "\"");
deletelink = UploadStatus.NA.getLocaleSpecificString();
NULogger.getLogger().log(Level.INFO, "Delete link : {0}", deletelink);
NULogger.getLogger().log(Level.INFO, "Download link : {0}", downloadlink);
downURL = downloadlink;
delURL = deletelink;
uploadFinished();
} catch(NUException ex){
ex.printError();
uploadInvalid();
} catch (Exception e) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, e);
uploadFailed();
}
}
@Override
public void run() {
try {
if (videoMegaAccount.loginsuccessful) {
userType = "reg";
httpContext = videoMegaAccount.getHttpContext();
maxFileSizeLimit = 5368709120L; // 5 GB
}
else {
host = "VideoMega.tv";
uploadInvalid();
return;
}
addExtensions();
//Check extension
if(!FileUtils.checkFileExtension(allowedVideoExtensions, file)){
throw new NUFileExtensionException(file.getName(), host);
}
if (file.length() > maxFileSizeLimit) {
throw new NUMaxFileSizeException(maxFileSizeLimit, file.getName(), host);
}
uploadInitialising();
initialize();
// //convert23.videomega.tv/upload.php
uploadURL = "http://" + StringUtils.removeFirstChars(uploadURL, 2);
// http://convert23.videomega.tv/upload.php
httpPost = new NUHttpPost(uploadURL);
MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
mpEntity.addPart("upload_hash", new StringBody(upload_hash));
mpEntity.addPart("converter", new StringBody(converter));
mpEntity.addPart("files", createMonitoredFileBody());
mpEntity.addPart("mupload", new StringBody(mupload));
httpPost.setEntity(mpEntity);
NULogger.getLogger().log(Level.INFO, "executing request {0}", httpPost.getRequestLine());
NULogger.getLogger().info("Now uploading your file into VideoMega.tv");
uploading();
httpResponse = httpclient.execute(httpPost, httpContext);
responseString = EntityUtils.toString(httpResponse.getEntity());
doc = Jsoup.parse(responseString);
//Read the links
gettingLink();
responseString = responseString.replaceAll("\\\\", "");
downloadlink = StringUtils.stringBetweenTwoStrings(responseString, "\"url\": \"", "\"");
deletelink = UploadStatus.NA.getLocaleSpecificString();
NULogger.getLogger().log(Level.INFO, "Delete link : {0}", deletelink);
NULogger.getLogger().log(Level.INFO, "Download link : {0}", downloadlink);
downURL = downloadlink;
delURL = deletelink;
uploadFinished();
} catch(NUException ex){
ex.printError();
uploadInvalid();
} catch (Exception e) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, e);
uploadFailed();
}
}
@Override
public void run() {
try {
if (filePupAccount.loginsuccessful) {
httpContext = filePupAccount.getHttpContext();
if(filePupAccount.isPremium())
maxFileSizeLimit = 5368709120L; // 5 GB
} else {
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
}
if (file.length() > maxFileSizeLimit) {
throw new NUMaxFileSizeException(maxFileSizeLimit, file.getName(), host);
}
uploadInitialising();
initialize();
httpPost = new NUHttpPost(uploadURL);
MultipartEntity uploadMpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
uploadMpEntity.addPart("upfile_" + System.currentTimeMillis(), createMonitoredFileBody());
httpPost.setEntity(uploadMpEntity);
NULogger.getLogger().log(Level.INFO, "executing request {0}", httpPost.getRequestLine());
NULogger.getLogger().info("Now uploading your file into FilePup.net");
uploading();
httpResponse = httpclient.execute(httpPost, httpContext);
gettingLink();
responseString = EntityUtils.toString(httpResponse.getEntity());
redirectUrl = StringUtils.stringBetweenTwoStrings(responseString, "'", "', 1");
responseString = NUHttpClientUtils.getData(redirectUrl, httpContext);
doc = Jsoup.parse(responseString);
downloadlink = doc.select("table.basic").select("input").first().attr("value");
deletelink = doc.select("table.basic").select("input").last().attr("value");
NULogger.getLogger().log(Level.INFO, "Download link : {0}", downloadlink);
NULogger.getLogger().log(Level.INFO, "Delete link : {0}", deletelink);
downURL = downloadlink;
delURL = deletelink;
uploadFinished();
} catch (NUException ex) {
ex.printError();
uploadInvalid();
} catch (Exception e) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, e);
uploadFailed();
}
}
@Override
public void run() {
try {
if (myDiscAccount.loginsuccessful) {
userType = "reg";
httpContext = myDiscAccount.getHttpContext();
sessionID = CookieUtils.getCookieValue(httpContext, "xfss");
maxFileSizeLimit = 5368709120L; //5 GB
} else {
userType = "anon";
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
maxFileSizeLimit = 5368709120L; //5 GB
}
if (file.length() > maxFileSizeLimit) {
throw new NUMaxFileSizeException(maxFileSizeLimit, file.getName(), host);
}
uploadInitialising();
initialize();
long uploadID;
Random random = new Random();
uploadID = Math.round(random.nextFloat() * Math.pow(10,12));
uploadid_s = String.valueOf(uploadID);
sess_id = StringUtils.stringBetweenTwoStrings(responseString, "name=\"sess_id\" value=\"", "\"");
srv_tmp_url = uploadURL;
if ("reg".equals(userType)){
uploadURL = StringUtils.removeLastChars(uploadURL, 3) + "cgi-bin/upload.cgi?upload_id=" + uploadid_s + "&js_on=1&utype=reg&upload_type=file";
}
else if ("anon".equals(userType)) {
uploadURL = StringUtils.removeLastChars(uploadURL, 3) + "cgi-bin/upload.cgi?upload_id=" + uploadid_s + "&js_on=1&utype=anon&upload_type=file";
}
//NULogger.getLogger().info("-----------Just before POST-----------");
//NULogger.getLogger().info(uploadURL);
httpPost = new NUHttpPost(uploadURL);
MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
mpEntity.addPart("js_on", new StringBody("1"));
mpEntity.addPart("upload_id", new StringBody(uploadid_s));
mpEntity.addPart("upload_type", new StringBody("file"));
mpEntity.addPart("utype", new StringBody(userType));
mpEntity.addPart("sess_id", new StringBody(sess_id));
mpEntity.addPart("srv_tmp_url", new StringBody(srv_tmp_url));
mpEntity.addPart("file_0_descr", new StringBody(""));
mpEntity.addPart("file_0_public", new StringBody("1"));
mpEntity.addPart("tos", new StringBody("1"));
mpEntity.addPart("link_rcpt", new StringBody(""));
mpEntity.addPart("link_pass", new StringBody(""));
mpEntity.addPart("file_0", createMonitoredFileBody());
mpEntity.addPart("submit_btn", new StringBody(""));
httpPost.setEntity(mpEntity);
NULogger.getLogger().log(Level.INFO, "executing request {0}", httpPost.getRequestLine());
NULogger.getLogger().info("Now uploading your file into MyDisc.net");
uploading();
httpResponse = httpclient.execute(httpPost, httpContext);
responseString = EntityUtils.toString(httpResponse.getEntity());
doc = Jsoup.parse(responseString);
//Read the links
gettingLink();
upload_fn = doc.select("textarea[name=fn]").val();
if (upload_fn != null) {
httpPost = new NUHttpPost("http://mydisc.net");
List<NameValuePair> formparams = new ArrayList<NameValuePair>();
formparams.add(new BasicNameValuePair("fn", upload_fn));
formparams.add(new BasicNameValuePair("op", "upload_result"));
formparams.add(new BasicNameValuePair("st", "OK"));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");
httpPost.setEntity(entity);
httpResponse = httpclient.execute(httpPost, httpContext);
responseString = EntityUtils.toString(httpResponse.getEntity());
//FileUtils.saveInFile("FileHoot.html", responseString);
doc = Jsoup.parse(responseString);
downloadlink = doc.select("textarea").first().val();
deletelink = doc.select("textarea").eq(3).val();
NULogger.getLogger().log(Level.INFO, "Delete link : {0}", deletelink);
NULogger.getLogger().log(Level.INFO, "Download link : {0}", downloadlink);
downURL = downloadlink;
delURL = deletelink;
uploadFinished();
}
} catch(NUException ex){
ex.printError();
uploadInvalid();
} catch (Exception e) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, e);
uploadFailed();
}
}
@Override
public void run() {
try {
if (letWatchAccount.loginsuccessful) {
httpContext = letWatchAccount.getHttpContext();
maxFileSizeLimit = Long.MAX_VALUE; // Unlimited
}
else {
host = "LetWatch.us";
uploadInvalid();
return;
}
addExtensions();
//Check extension
if(!FileUtils.checkFileExtension(allowedVideoExtensions, file)){
throw new NUFileExtensionException(file.getName(), host);
}
if (file.length() > maxFileSizeLimit) {
throw new NUMaxFileSizeException(maxFileSizeLimit, file.getName(), host);
}
uploadInitialising();
initialize();
long uploadID;
Random random = new Random();
uploadID = Math.round(random.nextFloat() * Math.pow(10,12));
uploadid_s = String.valueOf(uploadID);
uploadURL = uploadURL.replaceAll("upload_id", "X-Progress-ID");
uploadURL += uploadid_s + "&disk_id=" + disk_id;
// http://103.43.94.20/upload/01?upload_id=
// http://103.43.94.20/upload/01?X-Progress-ID=012386187335&disk_id=01
httpPost = new NUHttpPost(uploadURL);
MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
mpEntity.addPart("utype", new StringBody("reg"));
mpEntity.addPart("sess_id", new StringBody(sessionID));
mpEntity.addPart("srv_id", new StringBody(srv_id));
mpEntity.addPart("disk_id", new StringBody(disk_id));
mpEntity.addPart("file", createMonitoredFileBody());
mpEntity.addPart("fakefilepc", new StringBody(file.getName()));
mpEntity.addPart("file_title", new StringBody(removeExtension(file.getName())));
mpEntity.addPart("file_descr", new StringBody("Uploaded via Neembuu Uploader!"));
mpEntity.addPart("cat_id", new StringBody("0"));
mpEntity.addPart("file_public", new StringBody("1"));
mpEntity.addPart("file_adult", new StringBody("0"));
mpEntity.addPart("tos", new StringBody("1"));
mpEntity.addPart("submit_btn", new StringBody("Upload!"));
httpPost.setEntity(mpEntity);
NULogger.getLogger().log(Level.INFO, "executing request {0}", httpPost.getRequestLine());
NULogger.getLogger().info("Now uploading your file into LetWatch.us");
uploading();
httpResponse = httpclient.execute(httpPost, httpContext);
responseString = EntityUtils.toString(httpResponse.getEntity());
doc = Jsoup.parse(responseString);
//Read the links
gettingLink();
upload_fn = doc.select("textarea[name=fn]").val();
if (upload_fn != null) {
httpPost = new NUHttpPost("http://letwatch.us/");
List<NameValuePair> formparams = new ArrayList<NameValuePair>();
formparams.add(new BasicNameValuePair("fn", upload_fn));
formparams.add(new BasicNameValuePair("op", "upload_result"));
formparams.add(new BasicNameValuePair("st", "OK"));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");
httpPost.setEntity(entity);
httpResponse = httpclient.execute(httpPost, httpContext);
responseString = EntityUtils.toString(httpResponse.getEntity());
doc = Jsoup.parse(responseString);
downloadlink = doc.select("textarea").first().val();
deletelink = doc.select("textarea").eq(3).val();
NULogger.getLogger().log(Level.INFO, "Delete link : {0}", deletelink);
NULogger.getLogger().log(Level.INFO, "Download link : {0}", downloadlink);
downURL = downloadlink;
delURL = deletelink;
uploadFinished();
}
} catch(NUException ex){
ex.printError();
uploadInvalid();
} catch (Exception e) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, e);
uploadFailed();
}
}
/**
* Upload with normal uploader.
*/
public void normalUpload() throws IOException, Exception{
String uploadPostUrl;
NUHttpPost httppost;
HttpResponse response;
String reqResponse;
String doneURL;
String sessionID;
String authHash;
//Set the cookie store
cookieStore = new BasicCookieStore();
httpContext = new BasicHttpContext();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
httpclient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BEST_MATCH); //CookiePolicy
//Get the url for upload
reqResponse = NUHttpClientUtils.getData(uploadGetURL, httpContext);
//Read various strings
uploadPostUrl = StringUtils.stringBetweenTwoStrings(reqResponse, "'script' : '", "'");
authHash = StringUtils.stringBetweenTwoStrings(reqResponse, "auth_hash':'", "'");
doneURL = "http://www.sockshare.com/cp.php?uploaded=upload_form.php?done="+StringUtils.stringBetweenTwoStrings(reqResponse, "upload_form.php?done=", "'"); //Now find the done URL
NULogger.getLogger().log(Level.INFO, "Upload post URL: {0}", uploadPostUrl);
NULogger.getLogger().log(Level.INFO, "AuthHash: {0}", authHash);
NULogger.getLogger().log(Level.INFO, "Done URL: {0}", doneURL);
sessionID = CookieUtils.getCookieValue(httpContext, "PHPSESSID");
//Start the upload
uploading();
httppost = new NUHttpPost(uploadPostUrl);
ContentBody cbFile = createMonitoredFileBody();
MultipartEntity mpEntity = new MultipartEntity();
mpEntity.addPart("Filename", new StringBody(file.getName()));
mpEntity.addPart("fileext", new StringBody("*"));
mpEntity.addPart("do_convert", new StringBody("1"));
mpEntity.addPart("session", new StringBody(sessionID));
mpEntity.addPart("folder", new StringBody("/"));
mpEntity.addPart("auth_hash", new StringBody(authHash));
mpEntity.addPart("Filedata", cbFile);
mpEntity.addPart("Upload", new StringBody("Submit Query"));
httppost.setEntity(mpEntity);
response = httpclient.execute(httppost, httpContext);
reqResponse = EntityUtils.toString(response.getEntity());
if("cool story bro".equals(reqResponse)){
//Now we can read the link
gettingLink();
reqResponse = NUHttpClientUtils.getData(doneURL, httpContext);
downURL = "http://www.sockshare.com/file/"+StringUtils.stringBetweenTwoStrings(reqResponse, "<a href=\"http://www.sockshare.com/file/", "\"");
NULogger.getLogger().log(Level.INFO, "Download URL: {0}", downURL);
}
else{
//Handle errors
NULogger.getLogger().info(reqResponse);
throw new Exception("Error in sockshare.com. Take a look to last reqResponse!");
}
}
public static boolean uploadCustomFace(QQHttpClient httpClient,
String strFileName, String strVfWebQq, UploadCustomFaceResult result) {
try {
String url = "http://up.web2.qq.com/cgi-bin/cface_upload";
boolean bRet = httpClient.openRequest(url, QQHttpClient.REQ_METHOD_POST);
if (!bRet) {
return false;
}
httpClient.addHeader("Accept", "Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*");
httpClient.addHeader("Referer", "http://web2.qq.com/webqq.html");
httpClient.addHeader("Accept-Language","zh-cn");
httpClient.addHeader("Accept-Encoding","gzip, deflate");
httpClient.addHeader("Connection","keep-alive");
httpClient.addHeader("Cache-Control","no-cache");
//String strMimeType = GetMimeTypeByExtension(strFileName);
File file = new File(strFileName);
MultipartEntity mpEntity = new MultipartEntity();
ContentBody cbFile = new FileBody(file);
mpEntity.addPart("custom_face", cbFile);
ContentBody cbFile2 = new StringBody("EQQ.View.ChatBox.uploadCustomFaceCallback", Charset.forName(HTTP.UTF_8));
mpEntity.addPart("f", cbFile2);
ContentBody cbFile3 = new StringBody(strVfWebQq, Charset.forName(HTTP.UTF_8));
mpEntity.addPart("vfwebqq", cbFile3);
httpClient.setEntity(mpEntity);
//System.out.println("executing request " + );
httpClient.sendRequest();
int nRespCode = httpClient.getRespCode();
if (nRespCode != 200) {
httpClient.closeRequest();
return false;
}
byte[] bytRespData = httpClient.getRespBodyData();
httpClient.closeRequest();
if (!result.parse(bytRespData))
return false;
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
@Override
public void run() {
try {
if (multiUploadDotBizAccount.loginsuccessful) {
userType = "reg";
httpContext = multiUploadDotBizAccount.getHttpContext();
} else {
userType = "anon";
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
}
if (file.length() > maxFileSizeLimit) {
throw new NUMaxFileSizeException(maxFileSizeLimit, file.getName(), host);
}
uploadInitialising();
initialize();
httpPost = new NUHttpPost(uploadURL);
MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
// mpEntity.addPart("sess_id", new StringBody(sessionID));
mpEntity.addPart("remote", new StringBody("0"));
mpEntity.addPart("upload_id", new StringBody(uploadId));
mpEntity.addPart("files", new StringBody("1"));
mpEntity.addPart("file1", createMonitoredFileBody());
mpEntity.addPart("description1", new StringBody(""));
mpEntity.addPart("links", new StringBody(""));
//Adding all services
for(int i = 0; i < services.size(); i++){
mpEntity.addPart("site", new StringBody(services.get(i)));
}
httpPost.setEntity(mpEntity);
NULogger.getLogger().log(Level.INFO, "executing request {0}", httpPost.getRequestLine());
NULogger.getLogger().info("Now uploading your file into MultiUpload.biz");
uploading();
httpResponse = httpclient.execute(httpPost, httpContext);
//Read the links
gettingLink();
Header lastHeader = httpResponse.getLastHeader("Location");
if (lastHeader != null) {
downloadlink = lastHeader.getValue();
}
EntityUtils.consume(httpResponse.getEntity());
//FileUtils.saveInFile("MultiUploadDotBiz.html", responseString);
NULogger.getLogger().log(Level.INFO, "Download link : {0}", downloadlink);
downURL = downloadlink;
uploadFinished();
} catch(NUException ex){
ex.printError();
uploadInvalid();
} catch (Exception e) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, e);
uploadFailed();
}
}