我試圖讓Java做一個新的除了一個URL縮短,這是我有:爪哇 - 發送POST
private void sendPost() throws Exception {
String url = "http://shmkane.com/index.php?";
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("User-Agent", USER_AGENT);
con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
String urlParameters = "url=testingThis";
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();
int responseCode = con.getResponseCode();
System.out.println("\nSending 'POST' request to URL : " + url);
System.out.println("Post parameters : " + urlParameters);
System.out.println("Response Code : " + responseCode);
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println(response.toString());
}
我想爲它裝上去「form1的」,然後「提交」 here's the site
我對此很新,所以任何幫助都會很棒,可以告訴我我做錯了什麼或改進/修復了我目前的代碼。
你有什麼問題? –
我想這不是提交請求 – shmkane
它是否拋出異常?它是什麼輸出?你怎麼知道它不工作? –