从C - Terminal Ubuntu 16.04LTS中的HTTPS响应消息中获取cookie

时间:2016-07-26 20:43:02

标签: c cookies openssl httpresponse

处理HTTPS响应消息时遇到问题。我希望在收到的响应标题中从Set-Cookie字段中获取cookie的内容 这是我的功能:

ls

消息是我收到的回复消息。当我调用该函数时,我收到的结果是void Get_cookie(char *ck, char *message) { const int COOKIE_SIZE = 102400; int i, j, length = 0; char temp[] = "Set-Cookie: "; char cookie[COOKIE_SIZE]; char *start = NULL; char *msg = NULL; char *st = NULL; msg = strstr(message, temp); // find set-cookie in message if (msg == NULL){ // not found strcpy(ck, "null"); // return null return; } start = (char *) malloc(COOKIE_SIZE*sizeof(char)); strcpy(start, msg); // copy msg to start do { st = strstr(start, temp); // find set-cookie in start if (st == NULL) break; // don't have anymore => break st += strlen(temp); // move st pointer to content of feild i = 0; while (st[i] != '\n') i++; // find the character endline '\n' for (j = 0; j < i; j++) { // copy content to cookie cookie[length+j] = st[j]; } cookie[length+i] = ';'; // add ; length += (i + 1); start += (strlen(temp) + i + 1); // move start pointer to next feild } while (st != NULL); cookie[length] = '\0'; strcpy(ck, cookie); // return via ck printf("Cookie: \n%s\n", cookie); } 字符位于每行的开头(意外),如下所示:

在调整终端之前:

但奇怪的是,当我调整终端大小并再次运行程序时,我收到的结果是所有字符';'仍然在每行的头部。喜欢这个

调整终端后:

我不知道出了什么问题?我的代码或终端。请帮帮我。

0 个答案:

没有答案