当前页面: 开发资料首页 → JSP 专题 → 如何向biadu或google发送提交 post 信息,我写了怎么不行呀,有代码!
如何向biadu或google发送提交 post 信息,我写了怎么不行呀,有代码!
摘要: 如何向biadu或google发送提交 post 信息,我写了怎么不行呀,有代码!
向其他的服务器提交时可以,但是像摆渡的不行,急需要向摆渡提交信息,取得它的返回结果!
public String SendPost(String url) {
String result = "";
try {
URL httpURL = new URL("http://www.baidu.com");
HttpURLConnection httpConn = (HttpURLConnection)httpURL.openConnection();
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
httpConn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE5.5; Windows NT 5.0)");
httpConn.setRequestMethod("POST");
PrintWriter out = new PrintWriter(httpConn.getOutputStream());
out.write("s?wd=a&cl=3");
//out.print("s?wd=a&cl=3");
out.flush();
out.close();
BufferedReader in = new BufferedReader(new InputStreamReader(httpConn.getInputStream()));
String line = "";
while((line = in.readLine()) != null) {
System.out.println(line);
result += line;
}
in.close();
} catch (Exception e) {
System.out.println("没有结果" + e);
}
return result;
}
public String SendPost(String url) {
String result = "";
try {
URL httpURL = new URL("http://www.baidu.com");
HttpURLConnection httpConn = (HttpURLConnection)httpURL.openConnection();
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
httpConn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE5.5; Windows NT 5.0)");
httpConn.setRequestMethod("POST");
PrintWriter out = new PrintWriter(httpConn.getOutputStream());
out.write("s?wd=a&cl=3");
//out.print("s?wd=a&cl=3");
out.flush();
out.close();
BufferedReader in = new BufferedReader(new InputStreamReader(httpConn.getInputStream()));
String line = "";
while((line = in.readLine()) != null) {
System.out.println(line);
result += line;
}
in.close();
} catch (Exception e) {
System.out.println("没有结果" + e);
}
return result;
}
整理一下
我试了也是有的网站行,有的不行.关注!
如果调用google数据 可以直接用google的search serivce 不需要post
我直接调用他的url地址为什么提示
Server returned HTTP response code: 403 for URL: http://www.google.cn/search?q=abc&btnG=Google+%E6%90%9C%E7%B4%A2&meta=lr%3Dlang_zh-CN
我输入的是 abc
顶
mark
我也在写post方面的
能不能讲解一下 post方法的作用?我看了网上的一些资料还是不太清楚
可以就你的例子讲解下
比如 url=http://www.baidu.com
但是这句是什么意思呀 out.write("s?wd=a&cl=3");它要做什么?
先谢谢了
有qq吗 加我好不好
关注!!!
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setFollowRedirects(true);
conn.setInstanceFollowRedirects(false);
conn.setRequestProperty("User-Agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
conn.connect();
InputStream is = conn.getInputStream();
to blackren007008(风无影)
我的这段代码是向一个网站提交信息的!
out.write("s?wd=a&cl=3");
是一个提交的信息参数
是不是应该返回一个搜索后的结果?
我试了 好像还是搜索前的代码
能不能发份你的代码给我?
我的邮箱 blackren007008@gmail.com