互億無線 · 文檔中心

號碼標(biāo)記查詢 - 代碼示例


c++對接號碼標(biāo)記查詢接口DEMO示例
本文為您提供了C+6語言版本的號碼標(biāo)記查詢對接DEMO示例

號碼標(biāo)記查詢接口文檔 點(diǎn)擊下載

號碼標(biāo)記查詢接入指南 點(diǎn)擊訪問


// 接口類型:互億無線號碼標(biāo)記查詢接口
// 賬戶注冊:https://user.ihuyi.com/register.html
// 注意事項(xiàng):
// 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 = "/info_service/numbermark/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] = "