0

UPDATE: the POST request goes through just fine; the only problem is that when the input code (see below) runs, it posts the output of the input code rather than the input code itself even when the input code is commented out.

Input Code (zigzby): http://pastebin.com/5mZHpX7g was an earlier version of this program that I am using as the input.

Currently the output is "ha" on pastebin.com

Full Code: http://pastebin.com/qGiFUnyK

Specifically:

String zigzby = classEditor.getText(beginningLocation, endingLocation);
String encodedString = URLEncoder.encode(zigzby, "UTF-8");
encodedString = encodedString.replaceAll("%0A", "\r\n");
Scanner input = new Scanner(System.in);
System.out.println("Enter your pastebin code:");
String urlParameters = "api_option=paste&api_paste_code="+zigzby+"&api_dev_key=REVOKED&api_paste_expire_date=1M";
URL myURL = new URL("http://pastebin.com/api/api_post.php");
HttpURLConnection myURLConnection = (HttpURLConnection)myURL.openConnection();
myURLConnection.setDoOutput(true);
myURLConnection.setRequestMethod("POST");
myURLConnection.connect();

OutputStreamWriter writer = new OutputStreamWriter(myURLConnection.getOutputStream());

writer.write(urlParameters);
writer.flush();
maccaches
  • 1
  • 3
  • You need an HTTP Client to POST. see [1] [1]: http://stackoverflow.com/questions/6051648/httpclient-in-java – MarkOfHall Nov 23 '13 at 15:42
  • Just updated it to use an HTTP Client, but am still getting the same result. The code is posted on Pastebin, so the POST request is going through, but the posted code is the output of the program i'm trying to upload rather than it's code – maccaches Nov 25 '13 at 23:43

1 Answers1

0

Figured it out! When the input code was being fed in, I forgot that it contained POST parameters in it. These were included in the POST request, so that they were used rather than the original POST parameters.

maccaches
  • 1
  • 3