从标题中分离

时间:2011-03-28 23:08:25

标签: http-headers httprequest d

嘿伙计们。 我有这个功能:

我需要拆分标头和HTML。

string simpleGET(string url, string send) { 

    string headers;
    string buffer;
    TcpSocket socket;
    SocketStream socketStream;

    if(send is null) 
        headers = "GET / HTTP/1.1\r\nHost:"~url~"\r\nUConnection:close\r\n\r\n";
    else 
         headers = send;


    socket = new TcpSocket(new InternetAddress(url, 80));
    socket.send(headers);   
    socketStream = new SocketStream(socket);

    while(!socketStream.eof()){ 
                  //here filter, what is headers and the HTML
            buffer ~= socketStream.readLine() ~ "\r\n";

    }

    socketStream.close;
    socket.close;

        return buffer;
}

感谢,提前

1 个答案:

答案 0 :(得分:3)

你应该可以拆分两个\ r \ n序列

string[] parts = std.string.split(buffer, "\r\n\r\n")

parts [0]应该包含标题和部分[1]应该包含HTML