المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Submit a web form: What I'm doing wrong?



C++ Programming
08-27-2009, 04:23 PM
Hi everybody.

I want to submit a web form. Source of html page:





Name:
Age:






If I submit the form in the page above, I would get:

Welcome MyName!
You are 17 years old.


And this is my code:
CInternetSession session(L"MyAgent");
CHttpConnection* httpcon=session.GetHttpConnection(L"localhost");
CHttpFile* httpfile=httpcon->OpenRequest(CHttpConnection::HTTP_VERB_POST,L"i.php");
CString headers=L"Content-Type: application/x-www-form-urlencoded";
CString data=L"fname=MyName&age=17";
httpfile->SendRequest(headers,(LPVOID)(LPCTSTR)data,data.GetLength());
CString t=L"";
UINT len=100;
char buf[100];
while(len>0){
len=f->Read(buf,100);
if(len>0)t.Append(CString(buf),len);
}
AfxMessageBox(t);
httpfile->Close();
httpcon->Close();
session.Close();

Unfortunately, form is not being submitted. What I'm doing wrong?

I'm trying to do this thing 3rd time now, I don't want to give up this time http://barakasoft.com/script/Forums/Images/smiley_biggrin.gif

Any help would be greatly appreciated.