使用http协议 解析cJSON数据获取天气
使用localtime 获取当前时间
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <time.h>
#include "cJSON.h"
char *http_request = "GET /v3/weather/now.json?key=ShWvgorrEDvsykzw-&location=%s"
"&language=zh-Hans&unit=c HTTP/1.1\r\n"
"Host:api.seniverse.com\r\n\r\n";
int main(void)
{
//1.创建套接字,2.链接服务器, 3.发送数据、接收数据, 4.关闭套接字
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
if(sockfd < 0)
{
perror("socket");
return -1;
}
struct sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_po