Board index » cppbuilder » Example With WebPostData

Example With WebPostData


2005-10-17 10:53:52 PM
cppbuilder81
Novice User
Question regards "How to post data using TCppWebBrowser in C++Builder (bdn.borland.com/article/0,1410,27519,0.html)".
Can someone provide code showing how the function is called.
Here is something I am trying to figure out:
How do I value:
sURL
sPostData
Given the form on this page (www.gemdev.com/auctions/login.php)
presently I have
utils->WebPostData(bro,"gemdev.com/auctions/login.php",
"username=bea&password=[****]&login=Log in");
Thanks
...
This is the form from that page:
<form method="post" action="login.php?sid=8544d83f23a3049e19aa98d495a503f7">
<table width="100%" cellpadding="3" cellspacing="1" border="0" class="forumline">
<tr>
<td class="catHead" height="28"><a name="login"></a><span class="cattitle">Log in</span></td>
</tr>
<tr>
<td class="row1" align="center" valign="middle" height="28"><span class="gensmall">Username:
<input class="post" type="text" name="username" size="10" />
   Password:
<input class="post" type="password" name="password" size="10" maxlength="32" />
     Log me on automatically each visit
<input class="text" type="checkbox" name="autologin" />
<input type="submit" class="mainoption" name="login" value="Log in" />
</form>
 
 

Re:Example With WebPostData

"caleb" < XXXX@XXXXX.COM >wrote in message
Quote
Question regards "How to post data using TCppWebBrowser
in C++Builder (bdn.borland.com/article/0,1410,27519,0.html)".

Can someone provide code showing how the function is called.
Are you having any specific problems with the code that is provided in the
article?
Quote
How do I value:

sURL

sPostData

Given the form on this page (www.gemdev.com/auctions/login.php)
Like this:
utils->WebPostData(bro,"www.gemdev.com/auctions/login.php
46ecb6b387e9fba0948b39a03",
"username=joe&password=smoe&redirect=&login=Log%20in");
Gambit
 

Re:Example With WebPostData

"Remy Lebeau \(TeamB\)" < XXXX@XXXXX.COM >wrote:
someone provide code showing how the function is called.
Quote

Are you having any specific problems with the code that is provided in the
article?

No, not that I can tell, it compiles and navigates to the login page (below). I think it is the translation of the CGI form syntax -- that was my question. I believe the article code is not a problem.
Quote
>How do I value:
>
>sURL
>
>sPostData
>
>Given the form on this page (www.gemdev.com/auctions/login.php)

Like this:


utils->WebPostData(bro,"www.gemdev.com/auctions/login.php
46ecb6b387e9fba0948b39a03",
"username=joe&password=smoe&redirect=&login=Log%20in");


Thank you for the help.
It still navigates to the login page. The user is not logged in.
Is there a website or help page in BCB6 that explains how to convert the cgi form syntax to a URL?
Thanks
 

{smallsort}

Re:Example With WebPostData

Quote

Hello -- I used the onbeforenavigate2 event to see how it was being translated from CGI form. Thank you Gambit.
 

Re:Example With WebPostData

"caleb" < XXXX@XXXXX.COM >wrote in message
Quote
It still navigates to the login page. The user is not logged in.
That is likely. The "sid" value that the <form>appends to the URL appears
to be a dynamic value. Which means that you will have to first navigate to
"login.php" without a username/password, then grab the current SID, then
repost to login.php again with that value and the username/password. This
is exactly what happens when the user navigates to login.php and logs in
manually.
Quote
Is there a website or help page in BCB6 that explains how to convert
the cgi form syntax to a URL?
I don't think that has anything to do with your problem.
Gambit
 

Re:Example With WebPostData

"Remy Lebeau \(TeamB\)" < XXXX@XXXXX.COM >wrote:
Quote

"caleb" < XXXX@XXXXX.COM >wrote in message
news:4353f728$ XXXX@XXXXX.COM ...

>It still navigates to the login page. The user is not logged in.

That is likely. The "sid" value that the <form>appends to the URL appears
to be a dynamic value. Which means that you will have to first navigate to
"login.php" without a username/password, then grab the current SID, then
repost to login.php again with that value and the username/password. This
is exactly what happens when the user navigates to login.php and logs in
manually.
Even when using the sid value it does not successfully post the data.
When using the onbeforenavigate2 event to see the postdata when manually submitting the form, I noticed that the Headers were slightly different than if the form was posted with the function from the article. The text was slightly different and the manual post has an extra blank line in the headers:
Headers from manual post using the onbeforenavigate2 event to see the postdata:
Content-Type: application/x-www-form-urlencoded
[extra line]
Headers when using code from article:
Content-Type: application/x-www-form-urlencodedrn
---
I changed the article code to \r\n and it still navigated to the login page.
In the newsgroup archives there is mention of adding "\\" but I am not sure what they meant (Message-ID: < XXXX@XXXXX.COM >):
 

Re:Example With WebPostData

"caleb" < XXXX@XXXXX.COM >wrote in message
Quote
I changed the article code to \r\n and it still navigated to the login
page.
Did you try \r\n\r\n instead?
Quote
In the newsgroup archives there is mention of adding "\\" but I am not
sure what they meant
Yes you do. They are referring to the missing \ in the \r\n of the
header,which you've already corrected.
Gambit
 

Re:Example With WebPostData

"caleb" < XXXX@XXXXX.COM >wrote in message
Quote
Even when using the sid value it does not successfully post the data.
Did you do what I told you to do about getting the correct SID value each
time? You cannot just hard-code it. You have to pull in the HTML from
login.php and parse out the SID every time. What does your code look now?
Gambit
 

Re:Example With WebPostData

"Remy Lebeau \(TeamB\)" < XXXX@XXXXX.COM >wrote:
Quote

"caleb" < XXXX@XXXXX.COM >wrote in message
news:43565d65$ XXXX@XXXXX.COM ...

>Even when using the sid value it does not successfully post the data.

Did you do what I told you to do about getting the correct SID value each
time?
Yes -- definitely using the correct SID value each time.
Here is onbeforenavigate2 data it is adding to a tmemo:
Postdata:
username=bea&password=[removed]&redirect=&login=Log+in
TheURL:
gemdev.com/auctions/login.php
TheFlags:
0
TheTargetFrameName:
TheHeaders:
Content-Type: application/x-www-form-urlencoded
--
Tried both \r\n and \r\n\r\n. The former gives headers that match manual form submission.
--
this is what code looks like:
utils.WebPostData(bro,Edit1->Text, // gemdev.com/auctions/login.php
Edit2->Text); // username=bea&password=[removed]&redirect=&login=Log+in
// tried both Log+in and Log%20in
//////////// below is from article
::WebPostData(TCppWebBrowser * CppWebBrowser, String sURL, String sPostData)
{
BSTR bstrHeaders = NULL;
TVariant vFlags = {0}, vTargetFrameName={0}, vPostData={0}, vHeaders={0};
LPSAFEARRAY psa;
LPCTSTR cszPostData = sPostData.c_str();
UINT cElems = lstrlen(cszPostData);
LPSTR pPostData;
LPVARIANT pvPostData;
bstrHeaders = SysAllocString(L"Content-Type: application/x-www-form-urlencoded\r\n");
if (!bstrHeaders){
Application->MessageBox("Could not allocate bstrHeaders", "Warning", MB_OK | MB_ICONWARNING);
return;
}
V_VT(&vHeaders) = VT_BSTR;
V_BSTR(&vHeaders) = bstrHeaders;
pvPostData = vPostData;
if(pvPostData){
VariantInit(pvPostData);
psa = SafeArrayCreateVector(VT_UI1, 0, cElems);
if(!psa){
return;
}
SafeArrayAccessData(psa, (LPVOID*)&pPostData);
memcpy(pPostData, cszPostData, cElems);
SafeArrayUnaccessData(psa);
V_VT(pvPostData) = VT_ARRAY | VT_UI1;
V_ARRAY(pvPostData) = psa;
}
CppWebBrowser->Navigate((TVariant)sURL, &vFlags, &vTargetFrameName, &vPostData, &vHeaders);
}
 

Re:Example With WebPostData

"caleb" < XXXX@XXXXX.COM >wrote in message
Quote
Yes -- definitely using the correct SID value each time.
Are you absolutely sure about that? How EXACTLY are you getting the current
SID each time?
Quote
this is what code looks like:
You did not show the code that is retreiving the SID, or expain how the
TEdit objects are being filled in. All I can say is that other people have
reported the article's code works fine (with fix applied), so the only thing
I can think of is that either 1) your URL is still wrong when you post the
data, or 2) the server may require additional headers that you are not
including. Is the Content-Type on the only header that IE is submitting? I
would expect it to send more headers than that, such as Host, Referer, etc.
Gambit
 

Re:Example With WebPostData

"Remy Lebeau \(TeamB\)" < XXXX@XXXXX.COM >wrote:
Quote

"caleb" < XXXX@XXXXX.COM >wrote in message
news:4356850c$ XXXX@XXXXX.COM ...

>Yes -- definitely using the correct SID value each time.

Are you absolutely sure about that? How EXACTLY are you getting the current
SID each time?

100% sure -- SID copied and pasted from the VIEW SOURCE text into the tedit.
It works if I use ICS HTTP component to post the SID value and
form. You mention below that there may be other header
information, but when using ICS HTTPCli, the same info is
posted.
Quote
TEdit objects are being filled in. All I can say is that other people have
reported the article's code works fine (with fix applied), so the only thing
I can think of is that either 1) your URL is still wrong when you post the
data, or 2) the server may require additional headers that you are not
including. Is the Content-Type on the only header that IE is submitting?
Yes.
I
Quote
would expect it to send more headers than that, such as Host, Referer, etc.


Possibly, but it works with ICS HTTP post component sending the same info.
Perhaps you can try (user=rl&pass=gambit). I am not sure what
is the problem though I am highly confident the sid/url is
ok. It works with ICS sending the same information but the
article code would be nicer to use in many cases.
Thanks
 

Re:Example With WebPostData

"caleb" < XXXX@XXXXX.COM >wrote in message
Quote
It works if I use ICS HTTP component to post the SID value
and form.
Then you need to use a packet sniffer to compare the underlying HTTP traffic
that is generated by TCppWebBrowser and ICS to see what is different between
them.
Gambit