开发者

split from headers

开发者 https://www.devze.com 2023-02-20 04:48 出处:网络
Hey guys. I have this function: i need split headers and html. string simpleGET(string url, string send) {

Hey guys. I have this function:

i need split headers and html.

string simpleGET(string url, string send) { 

    string headers;
    string buffer;
    TcpSocket socket;
    SocketStream socketSt开发者_如何转开发ream;

    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;
}

thanks,advance.


You should be able to split on two \r\n sequences

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

parts[0] should contain headers and parts[1] should contain the HTML

0

精彩评论

暂无评论...
验证码 换一张
取 消