Posting to a form
C / C++ / MFC
1
Posts
1
Posters
0
Views
1
Watching
-
Hi, I would like to post a
. I think I have found the right way to do it, but it just will not work. It only works if I want to post an URL (like http://www.foo.com/res.asp&name=bart), but not if it is alot of text. Below is some sample code, that I would like to use for sending an SMS message programatically.
try{ CString strHeaders = \_T("Content-Type: application/x-www-form-urlencoded"); CString strFormData = \_T("afsender=boetos&modtager=5555554578&besked=this+is+a+test"); CInternetSession session; CHttpConnection\* pConnection = session.GetHttpConnection(\_T("212.112.128.11")); if (pConnection) { CHttpFile\* pFile = pConnection->OpenRequest(CHttpConnection::HTTP\_VERB\_POST, \_T("/res.asp")); ASSERT(pFile); BOOL result = pFile->SendRequest(strHeaders, (LPVOID)(LPCTSTR)strFormData, strFormData.GetLength()); if (result) { CString strData; CString strBuff; while (pFile->ReadString(strBuff)) { strData += strBuff; strBuff.Empty(); } //AfxMessageBox(strData); FILE \*f=fopen("res.html", "w"); if (f) { fprintf(f, strData); fclose(f); } AfxMessageBox("Done!"); pFile->Close(); delete pFile; } } pConnection->Close(); delete pConnection; } catch (CInternetException\* pEx) { // catch errors from WinINet pEx->ReportError(); pEx->Delete(); return; }
Can anybody tell me what goes wrong? Regards, Christian Skovdal Andersen