域名解析成IP
char szWeb[128] = "www.baidu.com";
struct hostent *pHost = NULL;
pHost = gethostbyname(szWeb);//完成主机名到域名的解析
char *IP = inet_ntoa(*((struct in_addr *)pHost->h_addr));
CString ipStr = IP;
请求三部曲:
1、CInternetSession session;
CInternetSession session;
session.SetOption(INTERNET_OPTION_CONNECT_TIMEOUT, 1000 * 20);
2、CHttpConnection* pConnection;
CHttpConnection* pConnection;
pConnection = session.GetHttpConnection(strServer, wPort);
3、pConnection->OpenRequest
//https
pConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST, ("post.do"), NULL, 1, NULL, NULL, INTERNET_FLAG_SECURE
| INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_RELOAD | INTERNET_FLAG_IGNORE_CERT_CN_INVALID | INTERNET_FLAG_IGNORE_CERT_DATE_INVALID);
//http
pConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST, ("post.do"));
4、pFile->SendRequest(szHeaders, (LPVOID)reqchar, strlen(reqchar));
pFile->SendRequest(szHeaders, (LPVOID)reqchar, strlen(reqchar));
5、pFile->QueryInfoStatusCode(dwRet)
https请求
CString strURL = "https://209.144.91.204:443/";
CString strServer, strObject;
INTERNET_PORT wPort;
DWORD dwType;
if (!AfxParseURL(strURL, dwType, strServer, strObject, wPort))
{
return false;//URL解析错误
}
pConnection = session.GetHttpConnection(strServer, wPort); //二、连接到Http服务器:
if (NULL == pConnection)
{
return false;
}
pFile = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST, ("/post.do"), NULL, 1, NULL, NULL, INTERNET_FLAG_SECURE
| INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_RELOAD | INTERNET_FLAG_IGNORE_CERT_CN_INVALID | INTERNET_FLAG_IGNORE_CERT_DATE_INVALID);
http请求
CString dnsUrl = ipStr + ":80";
pConnection = session.GetHttpConnection(url);
pFile = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST, ("/post.do"));
json解析
int len = pFile->GetLength();
char buf[2048];
int numread;
Json::Reader jsonReader;
Json::Value root;
while ((numread = pFile->Read(buf, sizeof(buf) - 1)) > 0)
{
buf[numread] = '';
strFile += buf;
}
if (lo服务器托管网g)
AfxMessageBox(strFile);
if (jsonReader.parse(buf, root)) {
int retCode = root["retcode"].asInt();
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.n服务器托管网et
算法小题 练习一: 需求: 键盘录入一些1~10日之间的整数,并添加到集合中。直到集合中所有数据和超过200为止。 代码示例: public class Test1 { public static void main(String[] args) { /* 键…