Never too old to learn.

http协议自学(4)

Posted on By Andy Zhu

继昨天的http协议中的cookies

现在我们需要知道服务端是怎么将要设置的cookies传回来的:

于是开始写代码:

uses zul_socket;
var
 a:Tclient;
 msg:ansistring;
begin
 a:=Tclient.create;
 a.host:='127.0.0.1';
 a.port:=8080;
 a.init;
 a.connect;
 writeln('connected');
 while true do
  begin
   a.send('GET / HTTP/1.1'+#13#10+'Host: localhost:8080'+#13#10+'Connection: keep-alive'+#13#10+'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8'+#13#10#13#10#13#10);
   msg:=a.recv;
   while msg<>'' do
    begin
     writeln(msg);
     msg:=a.recv;
    end;
  end;
end.

然后在IIS中弄一个页面,内容为:

<html>
    <head>
        <title>test</title>
        <meta charset="utf-8">
    </head>
    <body>
        <script>
            document.cookie="testhead=testvalue";
            document.cookie="test1=test2";
        </script>
    </body>
</html>

开启IIS服务

然后用上面给出的客户端连接,结果为:

HTTP/1.1 200 OK
Content-Type: text/html
Last-Modified: Sat, 20 Apr 2019 02:56:55 GMT
Accept-Ranges: bytes
ETag: "5a3ed1b624f7d41:0"
Server: Microsoft-IIS/10.0
X-Powered-By: ASP.NET
Date: Sat, 20 Apr 2019 03:11:35 GMT
Content-Length: 257

<html>
    <head>
        <title>test</title>
        <meta charset="utf-8">
    </head>
    <body>
        <script>
            document.cookie="testhead=testvalue"
            document.cookie="test1=test2";
        </script>
    </body>
</html>

然鹅它并没有使用一些奇奇怪怪的语法,就直接在html代码中传回来了。。。

似乎也没有什么不好的