out.println后要out.flush()的!
要么就
out = new PrintWriter(socket.getOutputStream(),true);

解决方案 »

  1.   

    请问楼上的!为什么out.println后要out.flush()呢?
      

  2.   

    改了
    out = new PrintWriter(socket.getOutputStream(),true);
    还是不行!
    有没这方面的源码啊?
      

  3.   

    还是先去查查HTTP的指令,我忘了!
      

  4.   

    在baidu上搜索了打半天都没找到合适的资料!
    POST /xxx.jsp HTTP/1.1
    Host: www.mywebsit.com
    Content-Length: <Content-Length>
    <param1>=<paramValue>
    这个格式是项目文档上的例子!我想应该是正确的把!
      

  5.   

    发送必须是这种格式的,特别是回车换行,多个少个都不行:
    POST http://news.sina.com.cn/c/2004-12-21/10084584671s.shtml HTTP/1.0
    User-Agent: myselfHttp/1.0
    Accept: www/source; text/html; image/gif; */*
    Host: news.sina.com.cn
    Content-type: application/x-www-form-urlencoded
    Content-length: 30alumniuname=kkk&alumniupwd=kkksource:
    import java.io.BufferedOutputStream;
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.net.InetAddress;
    import java.net.Socket;
    import java.net.URL;/*
     * Created on 2004-12-21
     * 
     * To change the template for this generated file go to Window - Preferences -
     * Java - Code Generation - Code and Comments
     *//**
     * @author Artimus
     * 
     * To change the template for this generated type comment go to Window -
     * Preferences - Java - Code Generation - Code and Comments
     */
    public class ConnectUrl {    private static final String OPEN_URL = "http://news.sina.com.cn/c/2004-12-21/10084584671s.shtml";    public static void main(String[] args) {
            Socket client = null;
            BufferedOutputStream sender = null;        try {
                URL webURL = new URL(OPEN_URL);
                InetAddress address = InetAddress.getByName(webURL.getHost());
                int portTemp = webURL.getPort();
                if (portTemp == -1) {
                    portTemp = 80;
                }
                client = new Socket(address, portTemp);
                String content = "alumniuname=kkk&";
                content += "alumniupwd=kkk";            String cmd = "POST " + OPEN_URL + " HTTP/1.0\r\n" + getBaseHeads();
                cmd += "Host: " + webURL.getHost() + "\r\n";
                cmd += "Content-type: application/x-www-form-urlencoded\r\n";
                cmd += "Content-length: " + content.length() + "\r\n\r\n";
                cmd += content + "\r\n";
                
    System.out.println(cmd);
    // sender = new BufferedOutputStream(client.getOutputStream());
                sender.write(cmd.getBytes(), 0, cmd.length());
                sender.flush();            BufferedReader out = new BufferedReader(new InputStreamReader(
                        client.getInputStream()));
                int b;
                String line = null;
                int i = 0;
                if (out != null) {
                    while ((line = out.readLine()) != null) {
                        System.out.println(line);
                    }
                    out.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                try {
                    if (client != null) {
                        client.close();
                        client = null;
                    }
                } catch (Exception e) {
                    // TODO: handle exception
                }
            }
        }
        /** **************************** */
        public static String getBaseHeads() {
            String inf = "User-Agent: myselfHttp/1.0\r\n"
                    + "Accept: www/source; text/html; image/gif; */*\r\n";
            return inf;
        }}
      

  6.   

    不好意思,这个不能注掉的:
    // sender = new BufferedOutputStream(client.getOutputStream());