1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
CString strData="<messages><accountreference>moncompte</accountreference><message><to>0611223344</to><body>texte du SMS</body></message></messages>";
CInternetSession session("SMS");
CHttpConnection *pSession=NULL;
CHttpFile *pFile=NULL;
int sockFail=0;
try
{
pSession=session.GetHttpConnection(192.168.5.5,INTERNET_FLAG_SECURE,80,NULL,NULL);
}
catch(CInternetException *pEx)
{
TCHAR sz[1024];
pEx->GetErrorMessage(sz,1024);
AfxMessageBox(sz,MB_ICONEXCLAMATION|MB_OK|MB_DEFBUTTON1);
pEx->Delete();
}
if(pSession)
{
CString header;
header="Content-Type: application/xml\r\n";
header+="<?xml version='1.0' encoding='UTF-8'?>\r\n";
header+="Authorization: Basic ";
//{
// char szBuffer[1024];
// CString strTmp;
// strTmp.Format("%s:%s",
// static_cast<LPCTSTR>(theApp.m_strEsendexUser),
// static_cast<LPCTSTR>(theApp.m_strEsendexPassword));
// StrToBase64(strTmp,szBuffer);
// header+=szBuffer;
//}
header+="user + mdp en base 64 (vérifié: le pb ne semble pas être ici)";
header+="\r\n";
try
{
DWORD dwFlags=INTERNET_FLAG_SECURE|INTERNET_FLAG_IGNORE_CERT_DATE_INVALID|INTERNET_FLAG_IGNORE_CERT_CN_INVALID;
pFile=pSession->OpenRequest(CHttpConnection::HTTP_VERB_POST,"https://api.esendex.com/v1.0/messagedispatcher",/*pstrReferer*/0,/*dwContext*/1,/*ppstrAcceptTypes*/0,"HTTP/1.1",dwFlags);
}
catch(CInternetException *pEx)
{
TCHAR sz[1024];
pEx->GetErrorMessage(sz,1024);
AfxMessageBox(sz,MB_ICONEXCLAMATION|MB_OK|MB_DEFBUTTON1);
pEx->Delete();
}
}
if(pFile)
{
try
{
pFile->AddRequestHeaders(header);
}
catch(CInternetException *pEx)
{
TCHAR sz[1024];
pEx->GetErrorMessage(sz,1024);
AfxMessageBox(sz,MB_ICONEXCLAMATION|MB_OK|MB_DEFBUTTON1);
pEx->Delete();
}
try
{
pFile->SendRequestEx(strData.GetLength());
pFile->WriteString(strData);
pFile->EndRequest();
}
catch(CInternetException *pEx)
{
TCHAR sz[1024];
pEx->GetErrorMessage(sz,1024); // ici, sz="Impossible d'établir une connexion avec le serveur"
AfxMessageBox(sz,MB_ICONEXCLAMATION|MB_OK|MB_DEFBUTTON1);
pEx->Delete();
}
CString retHeader;
pFile->QueryInfo(HTTP_QUERY_STATUS_CODE,retHeader,0);
if(retHeader!="200")
{
sockFail=1;
}
else
{
CString buff;
while(pFile->ReadString(buff))
{
strResponse+=buff;
strResponse+="\n";
buff.Empty();
}
}
pFile->Close();
delete pFile;
pSession->Close();
delete pSession;
} |
Partager