long PASCAL SendMessageSMS(char *CALLING_NBR,char *CALLING_PWD,char *CALLED_NBR,TCHAR *context,int PROXY_FLAG)
{
CInternetSession *pssion=NULL;
CHttpConnection *pconnet=NULL;
CHttpFile *pfile=NULL;
CString surl=_T("http://136.134.95.108:212/SendShortMessage");
DWORD DWSERVCETYPE=0;
CString sServer="";
CString sObject="";
CString shead="";
CString sresult="";
CString m_e1="";
CString m_e2="";
CString m_e3="";
CString m_e4="";
TCHAR buff[10240];
CString sdata="";
DWORD dwhttpstatus=0;
int nread=0;
INTERNET_PORT nport=80;
long count=0;
DWORD nf=HTTP_QUERY_RAW_HEADERS_CRLF;
m_e1=CALLING_NBR;
m_e2=CALLING_PWD;
m_e3=CALLED_NBR;
m_e4=context;
AfxMessageBox(m_e4);
//m_e4="中国五星红旗";
try
{
if (AfxParseURL(surl,DWSERVCETYPE,sServer,sObject,nport))
{
AfxMessageBox("1111");
if (PROXY_FLAG==0)
pssion=new CInternetSession(NULL,1,INTERNET_OPEN_TYPE_DIRECT);
else
pssion=new CInternetSession(NULL,1,INTERNET_OPEN_TYPE_PRECONFIG);
pconnet=pssion->GetHttpConnection(sServer,1,212,NULL,NULL);
pfile=pconnet->OpenRequest(CHttpConnection::HTTP_VERB_POST,sObject,NULL,1,NULL,NULL,INTERNET_FLAG_EXISTING_CONNECT|INTERNET_FLAG_RELOAD|INTERNET_FLAG_DONT_CACHE);
shead=_T("Accept:*/*\r\n"
"Content-Type:"
"application/x-www-form-urlencoded"
"\r\n");
sdata="senderNumber="+m_e1+"&password="+m_e2+"&receiverNumber="+m_e3+"&sendContent="+m_e4;
sdata=_T(sdata);
memset(buff,0,sizeof(buff));
strcpy(buff,sdata);
AfxMessageBox(buff);
pfile->SendRequest(shead,_T(buff),1000);
//pfile->SendRequest(shead,_T(buff),wcslen(buff));
pfile->QueryInfoStatusCode(dwhttpstatus);
if (dwhttpstatus>400)
{
AfxMessageBox("Send Message Fail!");
}
sresult="";
do
{
AfxMessageBox("4444");
memset(buff,0,sizeof(buff));
nread=pfile->Read(buff,10240);
if (nread!=0)
{
AfxMessageBox("5555");
buff[nread]=0;
sresult+=buff;
}
} while(nread!=0);
// MessageBox(sresult,"RESULT");
//AfxMessageBox("6666");
AfxMessageBox(sresult);
}
}
catch (CInternetException *e)
{
//pfile=NULL;
e->Delete();
delete pssion;
delete pconnet;
delete pfile;
return -1;
} //if (pfile)
//{
//AfxMessageBox("ok");
//}
//UpdateData(false);
delete pssion;
delete pconnet;
delete pfile;
return count;
}
{
CInternetSession *pssion=NULL;
CHttpConnection *pconnet=NULL;
CHttpFile *pfile=NULL;
CString surl=_T("http://136.134.95.108:212/SendShortMessage");
DWORD DWSERVCETYPE=0;
CString sServer="";
CString sObject="";
CString shead="";
CString sresult="";
CString m_e1="";
CString m_e2="";
CString m_e3="";
CString m_e4="";
TCHAR buff[10240];
CString sdata="";
DWORD dwhttpstatus=0;
int nread=0;
INTERNET_PORT nport=80;
long count=0;
DWORD nf=HTTP_QUERY_RAW_HEADERS_CRLF;
m_e1=CALLING_NBR;
m_e2=CALLING_PWD;
m_e3=CALLED_NBR;
m_e4=context;
AfxMessageBox(m_e4);
//m_e4="中国五星红旗";
try
{
if (AfxParseURL(surl,DWSERVCETYPE,sServer,sObject,nport))
{
AfxMessageBox("1111");
if (PROXY_FLAG==0)
pssion=new CInternetSession(NULL,1,INTERNET_OPEN_TYPE_DIRECT);
else
pssion=new CInternetSession(NULL,1,INTERNET_OPEN_TYPE_PRECONFIG);
pconnet=pssion->GetHttpConnection(sServer,1,212,NULL,NULL);
pfile=pconnet->OpenRequest(CHttpConnection::HTTP_VERB_POST,sObject,NULL,1,NULL,NULL,INTERNET_FLAG_EXISTING_CONNECT|INTERNET_FLAG_RELOAD|INTERNET_FLAG_DONT_CACHE);
shead=_T("Accept:*/*\r\n"
"Content-Type:"
"application/x-www-form-urlencoded"
"\r\n");
sdata="senderNumber="+m_e1+"&password="+m_e2+"&receiverNumber="+m_e3+"&sendContent="+m_e4;
sdata=_T(sdata);
memset(buff,0,sizeof(buff));
strcpy(buff,sdata);
AfxMessageBox(buff);
pfile->SendRequest(shead,_T(buff),1000);
//pfile->SendRequest(shead,_T(buff),wcslen(buff));
pfile->QueryInfoStatusCode(dwhttpstatus);
if (dwhttpstatus>400)
{
AfxMessageBox("Send Message Fail!");
}
sresult="";
do
{
AfxMessageBox("4444");
memset(buff,0,sizeof(buff));
nread=pfile->Read(buff,10240);
if (nread!=0)
{
AfxMessageBox("5555");
buff[nread]=0;
sresult+=buff;
}
} while(nread!=0);
// MessageBox(sresult,"RESULT");
//AfxMessageBox("6666");
AfxMessageBox(sresult);
}
}
catch (CInternetException *e)
{
//pfile=NULL;
e->Delete();
delete pssion;
delete pconnet;
delete pfile;
return -1;
} //if (pfile)
//{
//AfxMessageBox("ok");
//}
//UpdateData(false);
delete pssion;
delete pconnet;
delete pfile;
return count;
}
请高手们分析一下看那儿需要修改一下!