C/C++云通訊短信接口 demo:
正文:
#include <arpa/inet.h>
#include <assert.h>
#include <errno.h>
#include <netinet/in.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <netdb.h>
#include <unistd.h>
#define SA struct sockaddr
#define MAXLINE 4096
#define MAXSUB 2000
#define MAXPARAM 2048
#define LISTENQ 1024
//線上線下接口宏開(kāi)關(guān)
#define ONLINE
extern int h_errno;
int sockfd;
char *hostname = "123.59.105.84";
char *send_sms_uri = "/msg/send";
char *query_balance_uri = "/msg/balance";
/**
* * 發(fā)http post請(qǐng)求
* */
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: sms.253.com
"
"Content-type: application/x-www-form-urlencoded
"
"Content-length: %zu
"
"%s", page, strlen(poststr), poststr);
write(sockfd, sendline, strlen(sendline));
printf("
%s", sendline);
printf("
--------------------------
");
while ((n = read(sockfd, recvline, MAXLINE)) > 0) {
recvline[n] = '