C++???post HTTP???
???????????? ???????[ 2014/4/17 10:50:17 ] ????????C++ HTTP
#include <iostream>
#include <string>
using namespace std;
#include <afxinet.h>
bool PostHttpPage(const std::string& hostname??
const std::string& pathname??
const std::string& postdata)
{
CInternetSession session("your app agent name");
try
{
INTERNET_PORT nPort = 80;
DWORD dwRet=0;
CHttpConnection * pServer = session.GetHttpConnection(hostname.c_str()??nPort);
CHttpFile * pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST??pathname.c_str());
CString strHeader = "Content-Type: application/x-www-form-urlencoded"; // ?????
// ???????????
pFile->SendRequest(strHeader??(LPVOID)postdata.c_str()??postdata.size());
pFile->QueryInfoStatusCode(dwRet);
if (dwRet==HTTP_STATUS_OK)
{
CString strResult??strNewline;
while(pFile->ReadString(strNewline))
{// ?????????????
strResult += strNewline+"
";
}
std::cout<<strResult<<std::endl; // ???????????
}
else
{
return false;
}
delete pFile;
delete pServer;
}
catch (CInternetException * e)
{
// catch errors from WinInet
TCHAR pszError[200];
e->GetErrorMessage(pszError??200);
std::cout<<pszError<<std::endl; // ????????
return false;
}
session.Close();
return true;
}
int main(void)
{
string postdata = "?????????";
PostHttpPage("IP???"??"index.jsp?text=true"??postdata); // ????
//cout<<postdata<<endl;
getchar();
return 1;
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11