0

更新: POST 请求通过就好了;唯一的问题是,当输入代码(见下文)运行时,即使输入代码被注释掉,它也会发布输入代码的输出而不是输入代码本身。

输入代码(zigzby):http ://pastebin.com/5mZHpX7g是我用作输入的该程序的早期版本。

目前在 pastebin.com 上的输出是“ha”

完整代码: http: //pastebin.com/qGiFUnyK

具体来说:

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();
4

1 回答 1

0

弄清楚了!在输入输入代码时,我忘记了其中包含 POST 参数。这些都包含在 POST 请求中,因此使用它们而不是原始 POST 参数。

于 2013-11-26T00:49:41.007 回答