0
更新:POST請求經歷的很好;唯一的問題是,當輸入代碼(見下文)運行時,即使輸入代碼被註釋掉,它也會輸出輸入代碼的輸出,而不是輸入代碼本身。Java代碼:無法正確開機
輸入代碼(zigzby):http://pastebin.com/5mZHpX7g是此程序的早期版本,我將其用作輸入。
目前的輸出是 「哈」 在pastebin.com
全碼: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();
您需要HTTP客戶端進行POST。看到[1] [1]:http://stackoverflow.com/questions/6051648/httpclient-in-java – MarkOfHall
只是更新它使用HTTP客戶端,但仍然得到相同的結果。代碼發佈在Pastebin上,所以POST請求正在通過,但發佈的代碼是我試圖上傳的程序的輸出,而不是它的代碼 – maccaches