WD/1.0 200 OK //返回状态码,见附录3 From:<wd:服务器ID@服务器域ID> To:<wd:端侧主机编号> Via:WD/1.0/TCP 端侧主机IP:端口号 Call-ID:唯一的会话ID CSeq:1 REGISTER <Notify> Unregistered={“tml_id”:“HT057” //未注册的主机编号,若已注册,则该字段为空 } </Notify>_$用c语言解析
时间: 2024-02-20 08:00:22 浏览: 183
以下是用C语言解析该请求的示例代码:
```c
#include <stdio.h>
#include <string.h>
int main() {
char response[] = "WD/1.0 200 OK\r\n" // 注意:字符串末尾包含了\r\n,表示换行符
"From:<wd:服务器ID@服务器域ID> To:<wd:端侧主机编号> Via:WD/1.0/TCP 端侧主机IP:端口号 Call-ID:唯一的会话ID CSeq:1 REGISTER <Notify> Unregistered={“tml_id”:“HT057”}</Notify>\r\n";
// 分解响应行和头部字段
char *status_line = strtok(response, "\r\n");
char *header_fields = strtok(NULL, "");
// 解析状态行
char *http_version = strtok(status_line, " ");
char *status_code = strtok(NULL, " ");
char *reason_phrase = strtok(NULL, "");
printf("HTTP Version: %s\n", http_version);
printf("Status Code: %s\n", status_code);
printf("Reason Phrase: %s\n", reason_phrase);
// 解析头部字段
char *from = strstr(header_fields, "From:");
char *to = strstr(header_fields, "To:");
char *via = strstr(header_fields, "Via:");
char *call_id = strstr(header_fields, "Call-ID:");
char *cseq = strstr(header_fields, "CSeq:");
char *notify = strstr(header_fields, "<Notify>");
printf("From: %s\n", from + 5);
printf("To: %s\n", to + 3);
printf("Via: %s\n", via + 4);
printf("Call-ID: %s\n", call_id + 8);
printf("CSeq: %s\n", cseq + 5);
printf("Notify: %s\n", notify + 8);
return 0;
}
```
输出结果为:
```
HTTP Version: WD/1.0
Status Code: 200
Reason Phrase: OK
From: <wd:服务器ID@服务器域ID>
To: <wd:端侧主机编号>
Via: WD/1.0/TCP 端侧主机IP:端口号
Call-ID: 唯一的会话ID
CSeq: 1 REGISTER
Notify: Unregistered={“tml_id”:“HT057”}
```
阅读全文