前端
This commit is contained in:
Submodule
+1
Submodule www/cgi-bin/cJSON/cJSON added at cb8693b058
@@ -0,0 +1,9 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
printf("content-type: application/json; charset=utf-8\r\n");
|
||||
printf("\r\n\r\n");
|
||||
printf("{\"id\": 1, \"name\": \"disen\"}");
|
||||
return 0;
|
||||
}
|
||||
Executable
BIN
Binary file not shown.
+36
-2
@@ -1,9 +1,43 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <cjson/cJSON.h> // cjson 用于解析 json
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
printf("content-type: text/html;charset=utf-8\r\n");
|
||||
// 获取上传的数据
|
||||
char request_data[128] = "";
|
||||
fgets(request_data, 128, stdin);
|
||||
|
||||
// int fd = open("tmp.txt", O_RDWR | O_CREAT, 0666);
|
||||
// write(fd, request_data, strlen(request_data));
|
||||
|
||||
// 要求:请求上传的数据类型必须是 json 格式的字符串
|
||||
cJSON *p = cJSON_Parse(request_data);
|
||||
cJSON *name = cJSON_GetObjectItemCaseSensitive(p, "name");
|
||||
cJSON *pwd = cJSON_GetObjectItemCaseSensitive(p, "pwd");
|
||||
|
||||
printf("content-type: application/json;charset=utf-8\r\n");
|
||||
printf("\r\n");
|
||||
printf("<h3>请求成功,正在跳转主页</h3>");
|
||||
|
||||
if (strncmp(name->valuestring, "disen", 5) == 0 && strncmp(pwd->valuestring, "123123", 6) == 0)
|
||||
{
|
||||
printf("{\"code\":0,\"data\":{\"user_id\":111,\"nickName\":\"老狄\"}}");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("{\"code\":1,\"msg\":\"用户名或口令错误\"}");
|
||||
}
|
||||
|
||||
// write(fd, name->valuestring, strlen(name->valuestring));
|
||||
// write(fd, pwd->valuestring, strlen(pwd->valuestring));
|
||||
|
||||
// close(fd);
|
||||
|
||||
// json 对象中包含一个 data 对象
|
||||
return 0;
|
||||
}
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user