更新: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();
答案 0 :(得分:0)
想出来!当输入代码被输入时,我忘记它包含POST参数。这些都包含在POST请求中,因此使用它们而不是原始的POST参数。