用java向一个WEB发送psot请求
怎么才是连接成功 ,用不用在获得输入前加setdoinput(true)。
import java.net.*;
import java.io.*;
public class Test
{
public Test()
{
try
{
URL url = new URL( "http://www.xiaonei.com/Login.do ");
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), "8859_1 ");
out.write( "email=帐号&password=密码 ");
out.flush();
out.close();
//connection.setDoInput(true);
InputStreamReader read=new InputStreamReader(connection.getInputStream());
BufferedReader reader=new BufferedReader(read);
StringBuffer str =new StringBuffer();
System.out.println( "ok ");
while((reader.readLine())!=null)
{
str.append(reader);
}
System.out.println(str);
}catch(Exception e)
{
System.out.println( "mistake ");
}
}
public static void main(String[] args)
{
Test aa=new Test();
}
}
------解决方案--------------------顶了!