×

Loading...
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务

请教:http 协议中的 GET 语法

使用SOCKET 访问WEB SERVER 时候,中涉及到GET 和POST 的使用

其中访问WEB SERVER 中的WEB PAGE时候,后跟参数,其中有一项参数是
很长的字符串.

假设:
要访问的网页面是:
www.rolia.net/update.asp?sSql= select id from rolia.dbo.User_id
那么GET 语法怎么写?
我试验了以下
GET /update.asp?sSql=select id from rolia.dbo.User_id HTTP/1.0\r\nContent-Length: 0\r\n\r\n

但是反馈回来的错误的:
HTTP/1.1 400 Bad Request\r\nServer: Microsoft-IIS/5.0\r\nDate: Fri, 14 May 2004 19:37:34 GMT\r\nContent-Type: text/html\r\nContent-Length: 87\r\n\r\n<html><head><title>Error</title></head><body>The parameter is incorrect. </body></html>
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / 请教:http 协议中的 GET 语法
    使用SOCKET 访问WEB SERVER 时候,中涉及到GET 和POST 的使用

    其中访问WEB SERVER 中的WEB PAGE时候,后跟参数,其中有一项参数是
    很长的字符串.

    假设:
    要访问的网页面是:
    www.rolia.net/update.asp?sSql= select id from rolia.dbo.User_id
    那么GET 语法怎么写?
    我试验了以下
    GET /update.asp?sSql=select id from rolia.dbo.User_id HTTP/1.0\r\nContent-Length: 0\r\n\r\n

    但是反馈回来的错误的:
    HTTP/1.1 400 Bad Request\r\nServer: Microsoft-IIS/5.0\r\nDate: Fri, 14 May 2004 19:37:34 GMT\r\nContent-Type: text/html\r\nContent-Length: 87\r\n\r\n<html><head><title>Error</title></head><body>The parameter is incorrect. </body></html>
    • 你想黑我们rolia呀,还是想盗取个人信息?
      • 你也太会拍马屁了!"我们rolia呀" 它不是你的。呵呵! 是有些人的私家小花园。实话说,要黑了Rolia是分分秒秒的事。但我不想。
    • post sample code
      本文发表在 rolia.net 枫下论坛Socket sock;
      InputStream in;
      PrintWriter out;

      StringBuffer cmd = new StringBuffer( );
      StringBuffer contentStr = new StringBuffer( );
      String host = getParameter("host")==null?"localhost":getParameter("host");
      String port = getParameter("port")==null?"8540":getParameter("port");
      String channel = getParameter("channel")==null?"test_parserspy":getParameter("channel");

      /*String tt = "POST /servlet/pc\r\n";
      System.out.println(tt.length());
      for(int i=0; i< tt.length(); i++){
      System.out.print((int)tt.charAt(i)+" ");
      }*/
      cmd.append("POST /servlet/pc\r\n");
      cmd.append("Content-Type: multipart/form-data; boundary=-------------------987654d1f23\r\n");
      cmd.append("User-Agent: RawChannel\r\nContent-Length: ");

      contentStr.append("---------------------987654d1f23\r\n");
      contentStr.append("Content-Disposition: form-data; name=\"service\"\r\n\r\n");
      contentStr.append("localhost "+channel+"\r\n");
      contentStr.append("---------------------987654d1f23\r\n");
      contentStr.append("Content-Disposition: form-data; name=\"request\"\r\n\r\n");
      contentStr.append("<request version=\"1.0\"><query target=\"");
      contentStr.append("localhost "+channel+"\"");
      contentStr.append(" class=\"com.matrikon.pipe.kernel.request.RawDataQuery\"/></request>\r\n");
      contentStr.append("---------------------987654d1f23\r\n");
      cmd.append(contentStr.length()+"\r\n\r\n");
      cmd.append(contentStr.toString( ));

      try{
      sock = new Socket(host, Integer.parseInt(port));
      in = sock.getInputStream();
      out = new PrintWriter(sock.getOutputStream());
      out.print(cmd.toString());
      out.flush();

      System.out.println(cmd.toString( ));
      byte[] line = new byte[2000];
      int n;

      while((n = in.read(line)) != -1){
      parseXMLString(new String(line, 0, n)+"\r\n");
      while(pauseFlag == true) Thread.sleep(1000);
      }
      }
      catch(IOException e){
      System.out.println("Error: " + e);
      }
      catch(InterruptedException e){ }更多精彩文章及讨论,请光临枫下论坛 rolia.net
    • 用sniffer抓一下http的协议包,看看IE是怎么发Get请求的。
    • get is easy. To help u learn it by yourself. try this: c:\ telnet www.oracle.com 80 get index.html
      and also for u to do some reseach, here is a web server proxy server log(almost same)
      192.168.0.100 - - [18/May/2004:23:37:33 -0400] "GET http://ar.atwola.com/content/B0/0/H7pTL2Luf0_kw3xmlj8W1sns8a9RRNke8_SAqLzKBa609jmULHVa8jgFKtiL69KXJXfeocBApA1INUP0J9KQWQ5tQsT5x9SQ1VtZJocOjvI$/aol HTTP/1.0" 304 0
      cd:/srv/www/logs # 192.168.0.100 - - [18/May/2004:23:37:27 -0400] "GET http://ar.atwola.com/html/93169980/458898362/aol?SNM=HIDF&width=120&height=90&target=_blank&TZ=240&CT=I HTTP/1.0" 200 444
      -bash: 192.168.0.100: command not found
      192.168.0.100 - - [18/May/2004:23:37:33 -0400] "GET http://ar.atwola.com/content/B0/0/H7pTL2Luf0_kw3xmlj8W1sns8a9RRNke8_SAqLzKBa609jmULHVa8jgFKtiL69KXJXfeocBApA1INUP0J9KQWQ5tQsT5x9SQ1VtZJocOjvI$/aol HTTP/1.0" 304 0
      • below is the result, i tried. it can get web page. but wrong page. I think, it may caused by cookie problem. if i disable cookie of IE, I may get same page in IE.
        本文发表在 rolia.net 枫下论坛cd:/srv/www/logs # telnet rolia.net 80
        Trying 216.127.70.5...
        Connected to rolia.net.
        Escape character is '^]'.
        get /forum/forum_showPost.php?tno=209914&pno=1729028&

        <?xml version="1.0" encoding="ISO-8859-1"?>
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
        "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
        <head>
        <title>Cannot process request!</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <link rev="made" href="mailto:admin@localhost.net" />
        <style type="text/css">
        <!--
        body { color: #000000; background-color: #FFFFFF; }
        a:link { color: #0000CC; }
        -->
        </style>
        </head>

        <body>
        <h1>Cannot process request!</h1>
        <dl>
        <dd>


        The server does not support the action requested by the browser.

        </dd></dl><dl><dd>
        If you think this is a server error, please contact
        the <a href="mailto:admin@localhost.net">webmaster</a>

        </dd></dl>

        <h2>Error 501</h2>
        <dl>
        <dd>
        <address>
        <a href="/">default</a>
        <br />

        <small>Tue 18 May 2004 11:53:12 PM EDT</small>
        <br />
        <small>Apache/2.0.40 (Red Hat Linux)</small>
        </address>
        </dd>
        </dl>
        </body>
        </html>

        Connection closed by foreign host.
        cd:/srv/www/logs #更多精彩文章及讨论,请光临枫下论坛 rolia.net
    • 其实是把URL 中有空格的字符要写成%20 就可以了,其它有一些非字母的字符也要相应的转换.