C++對接手機號碼歸屬地查詢接口DEMO示例
本文為您提供了C++語言版本的IP地址查詢對接DEMO示例
// 接口類型:互億無線手機號歸屬地查詢接口
// 賬戶注冊:https://user.ihuyi.com/register.html
// 注意事項:
// DEMO僅作參考
//linux下的編譯:g++ ./test.cpp -o ./test
//linux下的執(zhí)行:chmod +x test &&./test
#include <arpa/inet.h>
#include
#include
#include <netinet/in.h>
#include
#include
#include
#include
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include
#include
#define SA struct sockaddr
#define MAXLINE 4096
#define MAXSUB 2000
#define MAXPARAM 2048
#define LISTENQ 1024
extern int h_errno;
int basefd;
char *hostname = "api.ihuyi.com";
char *submit_uri = "/appdev/mobile/Submit.json";
/**
* 發(fā)http post請求
*/
ssize_t http_post(char *page, char *poststr)
{
char sendline[MAXLINE + 1], recvline[MAXLINE + 1];
ssize_t n;
snprintf(sendline, MAXSUB,
"POST %s HTTP/1.0
"
"Host: %s
"
"Content-type: application/x-www-form-urlencoded
"
"Content-length: %zu
"
"%s", page, hostname, strlen(poststr), poststr);
write(basefd, sendline, strlen(sendline));
while ((n = read(basefd, recvline, MAXLINE)) > 0) {
recvline[n] = "