请大家帮帮忙 关于httpclient post的问题

boy_wh520 2008-07-18 08:09:17
现在要求 在http://www.yjgajj.com/wfcx.asp上用post方式获取查询信息 请各位取看一下http://www.yjgajj.com/wfcx.asp
这个页面 然后查询一下
我写了下面的方法利用post方式获取信息 为什么每次都显示"没有相关记录"

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);
}
...全文
184 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
kokobox 2008-07-18
  • 打赏
  • 举报
回复
用url可以实现,代码如下:

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();
}
zhangshenqiu 2008-07-18
  • 打赏
  • 举报
回复
路过学习一下
boy_wh520 2008-07-18
  • 打赏
  • 举报
回复
不需要的 你可以去http://www.yjgajj.com/wfcx.asp这里查询一下
直接点查询就有内容
interpb 2008-07-18
  • 打赏
  • 举报
回复
这个asp 要不要用户登录后才能访问
boy_wh520 2008-07-18
  • 打赏
  • 举报
回复
http://www.yjgajj.com/wfcx.asp上form

<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>
boy_wh520 2008-07-18
  • 打赏
  • 举报
回复
哈哈哈哈哈哈哈哈哈哈哈
boy_wh520 2008-07-18
  • 打赏
  • 举报
回复
继续顶 等到有人为止
boy_wh520 2008-07-18
  • 打赏
  • 举报
回复
没人?
boy_wh520 2008-07-18
  • 打赏
  • 举报
回复
顶一下
boy_wh520 2008-07-18
  • 打赏
  • 举报
回复
连IP138的内容都获取不到

81,115

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧