用HttpURLConnection向一个网页发送 POST请求?

Tony2251 2007-06-30 01:44:22
网页好像使用PHP做的,帮忙看看下面的代码,怎么老是返回登陆的界面?对编码有什么要求吗?
import java.net.*;
import java.io.*;


public class DoPostURLConnection
{
public static void main(String args[])
{
try{

URL url = new URL("http://www.xiaonei.com/Login.do");
HttpURLConnection uc =(HttpURLConnection) url.openConnection();
uc.setDoOutput(true);

OutputStream raw = uc.getOutputStream();
OutputStream buf = new BufferedOutputStream(raw);
OutputStreamWriter out = new OutputStreamWriter(buf, "UTF-8");


String info="email=email&password=ps";
out.write(info);
out.flush();
out.close();

InputStream in = uc.getInputStream();
in = new BufferedInputStream(in);
Reader r = new InputStreamReader(in,"UTF-8");
int c;
System.out.println("==================Beging====================");
while((c = r.read()) != -1)
System.out.print((char) c);
in.close();
System.out.println("===================End======================");

}
catch(IOException e){
System.out.println("no");
}
}
}

...全文
240 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

62,623

社区成员

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

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