Home > Back-end >  C write HTTP protocol request to the WEB server and accept the data
C write HTTP protocol request to the WEB server and accept the data

Time:11-22

Who knows the HTTP request how to write c + + write

CodePudding user response:

Use the interface implementation in the libcurl library, https://www.cnblogs.com/heluan/p/10177475.html

CodePudding user response:

GET/index. HTTP/1.1 HTM
Behind are some headers, Accept encoding and so on

CodePudding user response:

USES libcurl library will not use ah, put a piece of code that can access the server always return who help myself, be urgent!
CInternetSession m_cis;//used to create and initialize the Internet session yyf
CHttpConnection * m_pHttp;//for the HTTP service
Cstrings m_strIP, m_appliURL m_strIniPath;
INTERNET_PORT m_strport=80;
M_strIP="127.0.0.1";
M_appliURL="https://idserver.xxxkj.com";//the server address
If (m_appliURL. IsEmpty ())
{
//CHXcertinterfaceCtrl: : m_Geterror="connection address is empty";
return 2;
}

//DWORD dwType=AFX_INET_SERVICE_HTTPS;//the Internet server type
//AfxParseURL (m_appliURL, dwType m_strIP, m_strIniPath, m_strport);
//if (dwType!=AFX_INET_SERVICE_HTTP)
//{
////CHXcertinterfaceCtrl: : m_Geterror="connection URL is not begin with HTTP://";
//return 3;
//}

Cstrings SendInfo="client_id=Vuees& Client_secret=secret& The username=w001 & amp; Password=123123 & amp; Grant_type=password ";
M_strIniPath="https://idserver.xxxkj.com/connect/token?" ;
M_strIniPath=m_strIniPath + SendInfo;
M_cis. SetOption (INTERNET_OPTION_CONNECT_TIMEOUT, 5);//is used to specify the requirements set Internet options
M_cis. SetOption (INTERNET_OPTION_CLIENT_CERT_CONTEXT, 0);
M_pHttp=m_cis. GetHttpConnection (m_strIP m_strport);//is used to establish a HTTP connection, return a ChttpConnection function
CHttpFile * pFile=m_pHttp - & gt; OpenRequest (CHttpConnection: : HTTP_VERB_POST,
M_strIniPath, NULL, 1, NULL, NULL, INTERNET_FLAG_EXISTING_CONNECT);//open the HTTP server connection

DWORD dwRet=0;
DWORD szBuffer=0;
DWORD dwBufferSize=sizeof (szBuffer);

Try {
PFile - & gt; The SendRequest ();//send the request to the HTTP
PFile - & gt; QueryInfo (HTTP_QUERY_STATUS_TEXT, szBuffer, & amp; DwBufferSize);
PFile - & gt; QueryInfoStatusCode (dwRet);

} the catch (CInternetException * pEx)
{
TCHAR szError [1024].
PEx - & gt; GetErrorMessage (szError, 1024);
AfxMessageBox (szError);
PFile - & gt; Close ();

}
If (dwRet==HTTP_STATUS_OK)
{
Cstrings result, newline;
While (pFile - & gt; ReadString (newline))
{//loop reads each line
The result +=newline + "\ r \ n";
}
STD: : cout
}

CodePudding user response:

Always returns 404 this is the result of return


404 Not Found
<body bgcolor="white" & gt;

404 Not Found



Nginx/1.14.1 & lt;/center>


CodePudding user response:

My QQ 717807772

CodePudding user response:

Libcurl is very nice and very simple, a look at will, is nothing but a few function
Curl_easy_init
Curl_easy_setopt
Curl_easy_perform
curl_easy_cleanup

CodePudding user response:

Back to 404, this is a server page not found,
You can use the browser to https://idserver.xxxkj.com/connect/token? directly Try to see what was returned, if it can be normal visit, should be when joining together of the url you have the wrong, if the display page not found, it is that the server has a problem, you solve the problem of service side first, then the debugger,
  • Related