81,115
社区成员
发帖
与我相关
我的任务
分享
public static void main(String[] args) {
HttpClient client = new HttpClient();
String url = "http://www.yjgajj.com/wfcx.asp";
PostMethod postMethod = new PostMethod(url);
// 填入各个表单域的值
NameValuePair[] data = {new NameValuePair("leibie", "0"),
new NameValuePair("号牌号码", "吉H")};
// 将表单的值放入postMethod中
postMethod.setRequestBody(data);
// 执行postMethod
int statusCode = 0;
try {
statusCode = client.executeMethod(postMethod);
} catch (IOException ex) {
}
System.out.println(statusCode);
String str = "";
try {
str = new String(postMethod.getResponseBodyAsString().getBytes("ISO8859-1"));
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(str);
}
try{
StringBuffer temp = new StringBuffer();
String url = "http://www.yjgajj.com/wfcx.asp";
HttpURLConnection uc = (HttpURLConnection) new URL(url).openConnection();
uc.setConnectTimeout(10000);
uc.setDoOutput(true);
uc.setRequestMethod("POST");
uc.setUseCaches(false);
DataOutputStream out = new DataOutputStream(uc.getOutputStream());
// 要传的参数
String s = URLEncoder.encode("leibie", "GB2312") + "=" + URLEncoder.encode("0", "GB2312");
s += "&" + URLEncoder.encode("号牌号码", "GB2312") + "=" + URLEncoder.encode("吉H", "GB2312");
// DataOutputStream.writeBytes将字符串中的16位的unicode字符以8位的字符形式写道流里面
out.writeBytes(s);
out.flush();
out.close();
InputStream in = new BufferedInputStream(uc.getInputStream());
Reader rd = new InputStreamReader(in,"Gb2312");
int c = 0;
while ((c = rd.read()) != -1) {
temp.append((char) c);
}
in.close();
System.out.println( temp.toString());
}catch(Exception e) {
e.printStackTrace();
}
<form name=cxform method=post action="">
<td id=xiaoc style="word-break:break-all;line-height:150%" colspan="2">
<SELECT NAME="leibie" style="font-size:30px">
<OPTION VALUE="0">请选择号牌种类</OPTION>
<OPTION VALUE="1">小型汽车</OPTION>
<OPTION VALUE="2">大型汽车</OPTION>
<OPTION VALUE="3">两、三轮摩托车</OPTION>
</SELECT>
</TD><TD><INPUT style="font-size:30px" TYPE=TEXT name="号牌号码" value="吉H"></TD>
<td ><input style="font-size:30px" type=submit name="subtj" value="查询"></td>
</form>