大橙子网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

C++通过HTTP请求Get方式请求Json数据-创新互联

http://111.3.10.10:9123/yanfabu/getLckData1.php?type=update_wgjy_yfb&data={%22f_lckh%22:%222212052500%22,%22f_qty%22:36,%22f_hgqty%22:36,%22f_jyqty%22:3}

成都创新互联主营谢家集网站建设的网络公司,主营网站建设方案,手机APP定制开发,谢家集h5小程序开发搭建,谢家集网站营销推广欢迎谢家集等地区企业咨询
void CCM3600App::SendResERP(CString csResult)
{char Data[1024];
	WSADATA wData;
	::WSAStartup(MAKEWORD(2, 2), &wData);
	wchar_t* msg;
	DWORD dwNum;
	SOCKET Client_Sock = socket(AF_INET, 1, 0);
	struct sockaddr_in sin = {0 };
	int Ret = 0;
	int AddrLen = 0;
	HANDLE hThread = 0;
	WideCharToMultiByte(CP_ACP, 0, csResult, -1, Data, 1024, NULL, NULL);
	//拼接请求信息 //POST
	char send_str[2048] = {NULL };
	strcat(send_str, "GET ");
	strcat(send_str, "/yanfabu/getLckData1.php?");
	//strcat(send_str, "type=update_wgjy_yfb&data={%22f_lckh%22:%222212052500%22,%22f_qty%22:36,%22f_hgqty%22:36,%22f_jyqty%22:3}");
	strcat(send_str, "type=update_wgjy_yfb&data=");
	strcat(send_str, Data);
	strcat(send_str, " HTTP/1.1\r\n");
	strcat(send_str, "Connection:Keep-Alive\r\n");
	//strcat(send_str, "Content-Type:application/json\r\n");
	strcat(send_str, "Content-Type:text/html;charset=utf-8\r\n");
	strcat(send_str, "Accept-Encoding:gzip, deflate\r\n");
	strcat(send_str, "Accept-Language:zh-CN,en,*\r\n");
	strcat(send_str, "host:");
	//strcat(send_str, "192.168.1.100");
	strcat(send_str, "111.3.10.10");
	strcat(send_str, "\r\n");
	strcat(send_str, "User-Agent:Mozilla/5.0\r\n\r\n");
	char addIp[256] = {0 };
	//theApp.GetIpByDomainName("192.168.1.100", addIp);
	theApp.GetIpByDomainName("111.3.10.10", addIp);
	sin.sin_addr.s_addr = inet_addr(addIp);
	sin.sin_port = htons(9123);;
	sin.sin_family = AF_INET;
	char bufRecv[3069] = {0 };
	int errNo = 0;
	errNo = connect(Client_Sock, (sockaddr*)&sin, sizeof(sin));

	char cs_str[1024] = {NULL };
	char recv_str[8192] = {NULL };
	if (errNo == 0)
	{//如果发送成功,则返回发送成功的字节数;
		if (send(Client_Sock, send_str, strlen(send_str), 0) >0)
		{	m_SendOKorNO = 1;
		}
		else
		{	m_SendOKorNO = 0;
		}
		//如果接受成功,则返回接受的字节数;
		if (recv(Client_Sock, cs_str, 3069, 0) >0)
		{}
	}
	else
	{errNo = WSAGetLastError();
	}
	//接收正常拼接字符串
	strcat(recv_str, cs_str);
	memset(cs_str, 0, sizeof(cs_str));
	//只获取 报头信息后面的 返回值
	char* re_msg = strstr(recv_str, "\r\n\r\n");
	//转换字符串
	dwNum = MultiByteToWideChar(CP_UTF8, 0, re_msg, -1, NULL, 0);
	msg = new wchar_t[dwNum];
	MultiByteToWideChar(CP_UTF8, 0, re_msg, -1, msg, dwNum);

	//char*和CString的转换
	msg[dwNum] = '\0';
	CString str;
	str.Append(msg);
	g_csErpRecData = str;
	//关闭socket
	closesocket(Client_Sock);
	WSACleanup();
	//返回接收到的响应字符串
	return;
}

你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧


当前标题:C++通过HTTP请求Get方式请求Json数据-创新互联
新闻来源:http://dzwzjz.com/article/hosos.html
在线咨询
服务热线
服务热线:028-86922220
TOP