Prev: IVI
Next: PropertySHeet
From: Richard on
Hi,

I want to do a POST request using MFC. I have provided my code (so far)
below. I understand that I need to specify that it is a POST in the
constructor of CHttpFile - but as I create my CHttpFile instance ('file')
from CHttpConnection::OpenRequest() then I don't know how to specify that it
is a POST type.

Basically, what modification do I need to make to my code below so that I
can send "username=test&password=test" in the message body of a POST, and
get the server response returned?

Thanks.

========

void CHTTPTestDlg::GetHttpDataPostTest()
{
CHttpFile *file = NULL;
TRY
{
CInternetSession *session = NULL;
session = new CInternetSession();
CHttpConnection *connection = NULL;
char* server = "68.177.176.134";
char* login = "";
char* password = "";
char* path = "VoIPManagerWeb/Test";
connection = session->GetHttpConnection( server, 9100, login,
password );
file = connection->OpenRequest(1, path);
CString strRequestHeader = "Authorization: Basic ";
char* body = "username=test&password=test";
file->SendRequest(strRequestHeader,&body,25);
CString fullbody;
CString strSentence;
while(file->ReadString(strSentence))
{
fullbody = fullbody + strSentence;
}
m_strHttpContent = fullbody;
UpdateData(FALSE);

delete session;
}
CATCH(CInternetException, pEx)
{
MessageBox("Exception");
}
END_CATCH
}


From: Igor Tandetnik on
"Richard" <richard(a)hello.com> wrote in message
news:oPHdf.14798$wh7.9999(a)newsfe2-gui.ntli.net
> I want to do a POST request using MFC. I have provided my code (so
> far) below. I understand that I need to specify that it is a POST in
> the constructor of CHttpFile - but as I create my CHttpFile instance
> ('file') from CHttpConnection::OpenRequest() then I don't know how to
> specify that it is a POST type.

See KB Article KB165298 "How to simulate a Form POST request by using
WinInet".
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


 | 
Pages: 1
Prev: IVI
Next: PropertySHeet