ASP能接受SOCKET请求,不可能吧

解决方案 »

  1.   

    为什么不能?asp本身接收http1.1的请求,用Socket通道发送一个http的请求不可以吗?
      

  2.   

    HttpURLConnection urlConn; 
    DataOutputStream out; 
    DataInputStream in; 
    BufferedReader d; 
    System.out.println("Preparing the URL Connection"); 
    urlConn = (HttpURLConnection)url.openConnection(); 
    urlConn.setRequestMethod("POST"); 
    urlConn.setDoOutput(true); 
    urlConn.setDoInput(true); 
    urlConn.setUseCaches(false); 
    urlConn.setAllowUserInteraction(false); 
    System.out.println("Getting the output stream"); 
    out = new DataOutputStream( urlConn.getOutputStream ()); 
    System.out.println("Writing the bytes"); 
    out.writeBytes("toAsp=" + URLEncoder.encode("Ping Me")); 
    out.flush(); 
    out.close(); 
    System.out.println("Output stream sent"); 
    *** This is where the program fails ****** 
    in = new DataInputStream( urlConn.getInputStream() ); 
    System.out.println("Getting the input stream back"); 
    d = new BufferedReader(new InputStreamReader(in)); 
    System.out.println("Made buffered reader"); 
    System.out.println(d.readLine()); 
    d.close(); 
    in.close(); You can try this, maybe right, maybe wrong.
      

  3.   

    Mars_lee兄台,这个程序好像只是发送了一个url,而没有传递数据,是吗?
      

  4.   

    真麻烦,你用URL传送不就得了,还用这么费劲用socket?
    而且有时socket还受限制,吃力不讨好
      

  5.   

    请问你的目的是否是:ASP页面上有一个FORM等待提交,不过提交是由服务端通知客户端完成的!
    是吗?
      

  6.   

      看来robber老兄没有理解我的意思。ASP页面通常接收客户端的某个.html提交的数据,比如用户的注册。我只想模仿这个.html的作用而已。只是我只会用Get,不会用Post来请求这个asp.而get方法能传递的数据有限。 
      如果hangcom兄台不用Socket,只用url能解决这个问题当然最好。定高分奉送。  
      Mars_lee应该可以成功,只是我在urlConn.getOutputStream ()时不知怎么处理,还往指教。  
      

  7.   

    使用http协议肯定可以办到。
    首先这个socket的端口肯定是80或者是其他Web site的监听端口。
    然后按照Http协议的规范写你发送的数据包即可。不过太复杂。
      

  8.   

    Mars_lee的方法挺好的!
    你把你所要传输的数据向Stream中写即可。
    可是奇怪!程序怎么写成那样了?
      

  9.   

    利用Servlet来解决:public class ReceiptServlet extends HttpServlet {     public void doPost(HttpServletRequest request,
                           HttpServletResponse response)
    throws ServletException, IOException
        {
            ...
            // set content type header before accessing the Writer
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            
            // then write the response
            out.println("<html>" +
                        "<head><title> Receipt </title>" +
                        ...);
            
            out.println("<h3>Thank you for purchasing your books from us " +
                        request.getParameter("cardname") +
                        ...);
            out.close();
        }
        ...
    }不知道可否解决你的问题?
      

  10.   

    The code I've written is what I had found for you, not from me.
    It still has a bug, so, want everyone to see it, but maybe still can help you.
    good luck
      

  11.   

      感谢robber,感谢Mars_lee,我暂时用了Mars_lee的方法,挺好的。
      现在我正准备给asp页面提交一幅图像,希望成功!祝我好运。
      
      

  12.   

    Can you give me or us the code of yours?
    Thanks
      

  13.   

    你做的是applet吗?URL nt_action=null;
    DataInputStream dis;
    String temp_message="tempmessage";
    String temp_url_s;
    temp_url_s="xxx.asp?par1=xxx&par2=xxx&parN=xxx";//写上你的asp
    try{
    //temp_url_s 为调用action_to_nt 前设定的url暂时串
    nt_action=new URL(getDocumentBase(),temp_url_s);
    dis=new DataInputStream(nt_action.openStream());
    while((temp_message=dis.readLine())!=null){
    //temp_message 为取回的信息
    }dis.close();
    }catch(MalformedURLException e){
    //temp_message="MALerr";
    }catch(IOException e){
    //temp_message="IOerr";
    }
    可是这种方法似乎不应该能把file之类的东东传上去
      

  14.   

    用socket连接服务器80口
    发送命令
    POST (asp地址) HTTP/1.0
    Content-Length: parm=value&...(参数和值)
      

  15.   

        我已经试验过了,传送文件不可能成功,因为java的包功能的限制。
        现在正在尝试读rfc文档,因为文件的提交不太一样。很辛苦!有没有好方法?
      

  16.   

    www.servlets.com 上有解决文件的源码
      

  17.   

    在html中Form中的file组件在提交时能将客户端的文件上传到服务器端(而且似乎只有这种方法),所以只要在服务器端用request读上传后的数据原则上是可以的了!
      

  18.   

    你到底是用ASP还是用JAVA解决这个问题?POST不是很容易解决吗?我不明白你的POST是什么意思?难道不是FORM里面的ACTION=POST来定义的这个POST?
    如果你想上传文件也很简单啊,我做了个DLL文件,用来直接从FILE控件中读取文件,我不明白为什么要用SOCKET?
    真要用的话,就用VB写个DLL文件了。
      

  19.   

    你到底是用ASP还是用JAVA解决这个问题?POST不是很容易解决吗?我不明白你的POST是什么意思?难道不是FORM里面的ACTION=POST来定义的这个POST?
    如果你想上传文件也很简单啊,我做了个DLL文件,用来直接从FILE控件中读取文件,我不明白为什么要用SOCKET?
    真要用的话,就用VB写个DLL文件了。
      

  20.   

       看来我的表达能力确实比较差,或者我做的这个东东太特殊了。
       
       我的Post确实是FORM里面的ACTION=POST,可惜客户端不是浏览器,而是java的一个Code Behide 工程。服务器端asp 接收数据。所以需要java发送一个类似与html的 Http请求。现在解决不了文件。