我在套接字上接收到 HTTP 请求。
我想在 header 和内容处拆分 HTTP 请求。
所以,我尝试了这个来源。
//p is char* type, response too
p = strtok(response, "\r\n\r\n");
while(NULL != p){
printf("%s\n", p);
p = strtok(NULL, "\r\n\r\n");
}
但是 strtok()
也用 NULL
替换了 "\r\n"
。
我只想替换 "\r\n\r\n"
。
我该怎么办?
最佳答案
尝试 strstr
//p1 is char* type, response and p2 too
p1 = response;
p2 = strstr(response, "\r\n\r\n");
while(NULL != p2){
printf("%.*s\n", p2 - p1, p1);
p1 = p2;
p2 = strstr(p2 + 1, "\r\n\r\n");
}
关于c - 如何在 C 中拆分 HTTP header ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22732119/