Jump to content

Please help me to fix my article submitter script

- - - - -

  • Please log in to reply
No replies to this topic

#1
Csabi

Csabi

    Learning Programmer

  • Members
  • PipPipPip
  • 62 posts
Hi! I`m creating a script that will automatically submit my articles from my blog to article directories using java.
I`we created a php page: article.php?article=xxx and this page returns the necessary information about the article (e.g.: title, description, article image, article category)
Then using java I`we made a script that sends the article to various article directories, it creates cookies for sites that require registration with my username: I`we found the cookies in the following way: I log in to the article directory website from Firefox and I check what cookies where set by the website and using an HttpUrlConnection I recreate the cookies and send it.
My script works well with sites like tutorialkit.com and toxiclab.org but I can`t make it to work with tutorialized.com

Here is part of my script:

import java.io.*;

import java.net.*;


public class submit {

	

	String submit_url = null;

	String cookie = null;

	Boolean is_cookie = false;

	Boolean is_image = true;

	String image_field = null;

	String[] fields = new String[20];

	String[] fields_values = new String[20];

	int fields_nr;

	String image_mime;

	Boolean get_cookie = false;


	public void submit(String site){		

		

		tutorial tutorial = new tutorial();

		tutorial.get_tutorial(site);

		

		switch(tutorial.image_type){

			case ".jpg":

				image_mime = "image/jpeg";

				break;

			case ".png":

				image_mime = "image/png";

				break;

			case ".gif":

				image_mime = "image/gif";

				break;

		}

			

		switch(site){

			case "toxiclab":

				submit_url = "http://toxiclab.org/submit-tutorial.asp";

				cookie = "toxiclab=login=inf11652om";

				is_cookie = true;

				image_field = "myFile";

				fields[1] = "Name";

				fields_values[1] = tutorial.title;

				fields[2] = "Url";

				fields_values[2] = tutorial.url;

				fields[3] = "cat";

				fields_values[3] = tutorial.category;

				fields[4] = "Desc";

				fields_values[4] = tutorial.description;

				fields[5] = "categoryIds";

				fields_values[5] = "8";

				fields_nr = 5;

				break;

			case "tutorialkit":

				submit_url = "http://tutorialkit.com/submit.html";

				cookie = "login=csabi; passwd=xxxxxxx";

				is_cookie = true;

				image_field = "file";

				fields[1] = "title";

				fields_values[1] = tutorial.title;

				fields[2] = "url";

				fields_values[2] = tutorial.url;

				fields[3] = "act";

				fields_values[3] = "submit";

				fields[4] = "description";

				fields_values[4] = tutorial.description;

				fields_nr = 4;

				break;

				

		}

		

		System.out.print(site + ": ");

		

		if(tutorial.id > 0){

			try {

			

				URL url = new URL(submit_url);

				HttpURLConnection connection = (HttpURLConnection) url.openConnection();

		

				String line_end = "\r\n";

				String two_hyphens = "--";

				String boundary = "--*****";

				int bytesRead, bytesAvailable, bufferSize;

				byte[] buffer;

				int maxBufferSize = 1*1024*1024;

			

				connection.setRequestMethod("POST");

				connection.setDoOutput(true);

				connection.setDoInput(true);

				connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);

				if(is_cookie){

					connection.setRequestProperty("Cookie", cookie);

				}

				connection.setRequestProperty("USER-AGENT", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2");

				connection.setRequestProperty("Connection", "Keep-Alive");

				connection.setRequestProperty("Accept-Charset","iso-8859-1,*,utf-8");

				DataOutputStream httpStreamWriter = new DataOutputStream(connection.getOutputStream ());


				for(int i=1;i<=fields_nr;i++){

					httpStreamWriter.writeBytes(two_hyphens + boundary + line_end);

					httpStreamWriter.writeBytes("Content-Disposition: form-data; name=\"" + fields[i] + "\"" + line_end);

					httpStreamWriter.writeBytes("Content-Type: text/plain; charset=iso-8859-1" + line_end);

					httpStreamWriter.writeBytes(line_end);

					httpStreamWriter.writeBytes(fields_values[i]);

					httpStreamWriter.writeBytes(line_end);

				}

			

				if(is_image){

					httpStreamWriter.writeBytes(two_hyphens + boundary + line_end);

					httpStreamWriter.writeBytes("Content-Disposition: form-data; name=\"" + image_field + "\"; filename=\"D:/Work/Thumbnails/" + tutorial.id + tutorial.image_type + "\"" + line_end);

					httpStreamWriter.writeBytes("Content-Type: " + image_mime + line_end + line_end);

			

					FileInputStream fileInputStream = new FileInputStream(new File("D:/Work/Thumbnails/" + tutorial.id + tutorial.image_type));

					bytesAvailable = fileInputStream.available();

					bufferSize = Math.min(bytesAvailable, maxBufferSize);

					buffer = new byte[bufferSize];

            

					bytesRead = fileInputStream.read(buffer, 0, bufferSize);

					while(bytesRead > 0) {

						httpStreamWriter.write(buffer, 0, bufferSize);

						bytesAvailable = fileInputStream.available();

						bufferSize = Math.min(bytesAvailable, maxBufferSize);

						bytesRead = fileInputStream.read(buffer, 0, bufferSize);

					}

				}

			

				httpStreamWriter.writeBytes(line_end);

				httpStreamWriter.writeBytes(two_hyphens + boundary + two_hyphens + line_end);

			

				httpStreamWriter.flush ();

				httpStreamWriter.close ();

				

				connection.connect();


				BufferedReader bufferr = new BufferedReader(new InputStreamReader(connection.getInputStream()));

				String line;

				while ((line = bufferr.readLine()) != null) {

				

					System.out.println(line);

				

				} 

				System.out.println();

				System.out.println();

				

				for(int i = 0;i<50;i++){

					System.out.println(connection.getHeaderFieldKey(i) + " = " + connection.getHeaderField(i));

				}

				

				URL url2 = new URL("http://www.tutorialswindow.com/admin/outside_submitter_action_submit.php?site=" + site + "&tutorial=" + tutorial.id);

				URLConnection connection2 = url2.openConnection();

				connection2.connect();

				

				BufferedReader bufferr2 = new BufferedReader(new InputStreamReader(connection2.getInputStream()));

				String line2;

				while ((line2 = bufferr2.readLine()) != null) {

				

					System.out.println(line2);

				

				} 

				System.out.println();

				System.out.println();

	

			}

			catch(Exception e){

				e.printStackTrace();

			}

		}

		else if(tutorial.id == 0){

			System.out.println("No more tutorials to submit");

		}

		else if(tutorial.id == -1){

			System.out.println("Fast submission");

		}

		

	}


}

Please help me to find out how to make the script to work with tutorialized.com, too, because that would be the most important site. I`we checked with Fiddler what request is sent to the server when I submit a tutorial manually from any browser and I`we seen that there are always two more values: x and y, with different number values and it submits the tutorial only if the x and y numbers are correct, but I don`t know how are generated, please help me to figure it out!
x and y act like a simple text input, but in the website source code I can`t find any fields with this name....
Thanks!




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users