用java向web站点发送post请求。

zyzyy 2007-06-04 02:13:42
web站点是不是直接的request。getParameter(“name”)就可以接受到阿。为什么我接收到的总是null?
...全文
437 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
maomaoliu 2007-06-05
  • 打赏
  • 举报
回复
未发现错误
conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");可以不设置
zyzyy 2007-06-05
  • 打赏
  • 举报
回复
dataOutStream.writeBytes("username=bob&password=232"); 这个位置给username负值了 username=bob
问题解决了。
eunice_zrx 2007-06-05
  • 打赏
  • 举报
回复
同意duncan301的,没发现你什么地方给username赋值
iwillrockyou 2007-06-04
  • 打赏
  • 举报
回复
帮顶
seablue_xj 2007-06-04
  • 打赏
  • 举报
回复
楼上正解
duncan301 2007-06-04
  • 打赏
  • 举报
回复
你set"username"这个属性值了么?比如http://localhost:8080/aa/aaa.jsp?username="liuyun",在request作用范围内有这个键值才能取的到啊
zyzyy 2007-06-04
  • 打赏
  • 举报
回复
有什么错误么?
zyzyy 2007-06-04
  • 打赏
  • 举报
回复
我这么写的。 服务器端
System.out.println("doPost!@!!!!!!!!!!!!!!!!!!!!!");
response.setContentType("text/html; charset=UTF-8");
response.setHeader("Cache-Control", "no-cache");

try {
System.out.println(request.getContentType().toString()
+ "---getContentType");
System.out.println(request.getParameter("username") + "---getParameter");
的不到这个username的值,取得是null
zyzyy 2007-06-04
  • 打赏
  • 举报
回复
conn = (HttpURLConnection) target.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("Connection", "Keep-Alive");
dataOutStream = new DataOutputStream(conn.getOutputStream());
dataOutStream.writeBytes("username=bob&password=232");
dataOutStream.flush();
dataOutStream.close();
DBA_DREAM 2007-06-04
  • 打赏
  • 举报
回复
yes

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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