你是怎样模拟post的?
既然URLConnection可以,为什么不用?

解决方案 »

  1.   

    可能因为你的HTTP REQUEST 的头部有这样的
    Connection:close
    所以输入流就关了400 是Bad Request,当把 http/1.0改为 http/1.1时,可能是WEBSERVER不支持HTTP/1。1所以就会出现这样的问题。
    你可以看看RFC1945(HTTP/1。0)和RFC2068(HTTP/1。1)
      

  2.   

    URLConnection 不能做超时,即使想办法做出来效率也很差即使没有 connection:close,输入流照样是关闭
    这个字段的含义是指出在把数据全部发送到客户端后服务器端关闭连接吧?服务器端还没有把所有的数据都接受完怎么就能关闭输入流呢?(我对http协议没有深入研究,这是我的理解不知对不对)webserver 对 http/1.1 是完全支持的,这从sun对 HttpURLConnection 的实现上能够确定,HttpURLConnection实现的就是 1.1版我想是不是某些字段没有设置造成这种情况的
    另外上面的程序在windows平台上可以正常执行但是在unix平台上就不行还请高手继续指点
    继续感谢!
      

  3.   

    另:有没有http1.0 /1.1 中文版电子文档下载,看英文太困难
    email:[email protected]
    非常感谢
      

  4.   

    代码如下        PrintStream out=null;
            BufferedReader is=null;
    try
    {
                url=new URL(strUrl);
                int port=url.getPort();
                if(port==-1) port=80;
                String host=url.getHost();
                String file=url.getFile();
                if(file.equalsIgnoreCase(""))file="/";
                socket=new Socket(host,port);
                socket.setSoTimeout(timeout);            out=new PrintStream(new BufferedOutputStream(socket.getOutputStream()));            int len=toGMLC.length();
                String head="POST "+file+" HTTP/1.1\r\n";
                head+="Content-type:application/x-www-form-urlencoded\r\n";
                head+="Content-Length:"+len+"\r\n";
                head+="\r\n";            head+=toGMLC;
                out.print(head);
                out.flush();
                is=new BufferedReader(new InputStreamReader(socket.getInputStream()));
                String s="",s2="";
                while((s=is.readLine())!=null)
                {
                    s2+=s+"\r\n";
                }
                int pos=s2.indexOf("\r\n\r\n");
                fromGMLC=s2.substring(pos+4);
            }catch(InterruptedIOException e2){
                iserr=true;
                errId=1;
                err="请求数据超时";
    }catch(Exception ex){
    iserr=true;
                errId=2;
    err=ex.toString();
    }finally{
                try{
                    if(socket!=null)socket.close();
                }catch(Exception e){}
                return fromGMLC;
            }
    }
      

  5.   

    以下只是我的建议。
    1:在JAVA中,"\r\n"好象不是CRLF(两个字节),是4个字节 
    2:我认为你的REQUEST 数据应该用“iso-8859-1”编码。
    3:去掉socket.setSoTimeout(timeout);这一句试试。
      

  6.   

    现在的问题是:
    客户端接收从服务器端发来的数据是没有问题的是服务器端的sevlet从自己的输入流读取数据时出问题
      

  7.   

    把int len = toGMLC.length();
    改成int len = toGMLC.getBytes().length;试试呢?