Http post not working
Sep 6, 2010 at 9:39am UTC
Hello guys. I am trying to post an HTML form to a .aspx webpage but the aspx page is not recieving the parameters. Here is the c++ code
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
CString request;
request.Format("<FORM method=POST action='http://localhost/submit'>"
"<input type='hidden' name='number' value='%s'>"
"<input type='hidden' name='client' alue='help'>"
"<input type='hidden' name='key' alue='d1a6701ecad7d2d1ab5f32d448a72949b334cd38'>"
"</FORM>" , pnum);
DWORD dwStat;
CInternetSession sess;
CHttpConnection* hConn = sess.GetHttpConnection("localhost" , INTERNET_DEFAULT_HTTP_PORT, "" );
CHttpFile* file = hConn->OpenRequest(CHttpConnection::HTTP_VERB_POST, "/submit/default.aspx" , NULL,1,NULL,NULL,INTERNET_FLAG_EXISTING_CONNECT);
CString strHeaders = _T("Content-Type: application/x-www-form-urlencoded" );
file->SendRequest(strHeaders, (LPVOID)(LPCSTR)request, request.GetLength());
file->QueryInfoStatusCode(dwStat);
CString code; code.Format("%d" , dwStat);
theProc.Message(LOG_INFO, "Code: " + code);
if (dwStat == 200) //REQUEST SENT SUCCESSFUL
{
CString cLine;
CString cStr;
while (file->ReadString(cLine))
cStr += cLine+"\r\n" ;
}
When i run this i get Code 200 returned but in the response the values i posted are NULL
Here is how i check them in aspx
1 2 3 4 5 6 7 8 9 10 11 12 13
if (Request.Form["number" ] != null && Request.Form["client" ] != null && Request.Form["key" ] != null)
{
//Response.ContentType = "text/plain";
Response.Write(Request.Form["number" ].ToString() + "<br>" );
Response.Write(Request.Form["client" ].ToString() + "<br>" );
Response.Write(Request.Form["key" ].ToString() + "<br>" );
}
else
{
//Response.ContentType = "text/plain";
Response.Write("1" );
}
So the response in the page is 1.
Any advise on what i am doing wrong?
Thanks
Sep 6, 2010 at 3:40pm UTC
request.Format("<FORM method=POST action='http://localhost/submit'>"
"<input type='hidden' name='number' value='%s'>"
"<input type='hidden' name='client' alue ='help'>"
"<input type='hidden' name='key' alue ='d1a6701ecad7d2d1ab5f32d448a72949b334cd38'>"
"</FORM>", pnum);
I think you mean
value and not
alue .
Last edited on Sep 6, 2010 at 3:41pm UTC
Sep 7, 2010 at 6:59am UTC
yes its sais value in the code. its just mistype here.
So still no tips for solution guys?
Sep 7, 2010 at 7:45am UTC
I'm not good with Windows stuff. But are you really supposed to be sending a HTML form here? I would have thought it is expecting a QUERY STRING stuffed with the form data:
request.Format("number=%s&client=help&key=d1a6701ecad7d2d1ab5f32d448a72949b334cd38" , pnum);
Sep 7, 2010 at 7:56am UTC
wow. this actually worked. i thought it would also work with html form but i guess i was wrong.
Thanks alot
Sep 7, 2010 at 8:13am UTC
Topic archived. No new replies allowed.