Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem using webbrowser 2

Status
Not open for further replies.

rha2000

Programmer
Aug 6, 2012
14
AR
I need to pass POST parameters using VFP9 and does not work.

PostData = "data=LaInformacionQueQuieroEnviar"
PostData = StrConv(PostData ,5)
Headers = "Content-Type: application/x- + CHR(13) + CHR(10)
thisform.Webbrowser1.Navigate( url, 0, "", PostData, Headers)

I think the problem is the StrConv function.

Any ideas?

Thanks
 
You nbeed CreateBinary here, not Strconv(). The option you chose creates Unicode, but POST data must be passed in as a binary byte array. This is done by VFP, if using CREATEBINARY().

For example do this:

Postdata = CREATEBINARY("test='1'")
Thisform.Webbrowser1.Navigate(" application/x-
You may or may not additionally convert your text/formdata to unicode, but typically you would take UTF-8, not Unicode.

httpbin.org is a test server letting you test requests, not just post, see
You will get a download dialog, as the response is handled as a file without file extension called "post". Therefore I fiond it easier to make use of oHttpRequest = CREATEOBJECT("microsoft.xmlhttp")

Bye, Olaf.
 

Hi Olaf, you say it all in your response, but to put it a little clear:

[ul]
[li]The createbinary function is a requirement for the browser control
( Navigate Method (String, String, Byte[], String) ).[/li]

[li]The post data must be a "safe url encoded" string, as stated on the http header [/li]
[li]Preferably encode as utf-8 before url-encode the post data[/li]
[li]If you use microsoft.xmlhttp there's no need to use createbin, just post the url encoded data as string.[/li]
[/ul]

Marco




 
Thanks for the folow up, Marco.
But you're not getting the point about microsoft.xmlhttp post requests.

If you open and send a POST request you also need to use CREATEBINARY for the post data, if you use the url to append parameters, this is just sending no post data via the post request, it's just piggyback GET data put into the destination.

I haven't tested how this arrives in eg PHP as $_POST or $_GET, but the real deal is sending the post data via oRequest.open("POST",url), then set headers via oRequest.setRequestHeader() and finally oRequest.send(CreateBinary(postdata))

Bye, Olaf.
 
Just tested with again:

o = CreateObject("microsoft.xmlhttp")
o.open("POST","o.send()
do while o.readystate<>4
doevents force
enddo
? o.responseText

o.open("POST","o.send(CreateBinary("test=42")
do while o.readystate<>4
doevents force
enddo
? o.responseText

See the difference in the response texts. In case of url appended parameters they arrive in the args, not as sent data.
When using post to post eg files, an image, you better not do that via the url, but in the post body.

Bye, Olaf.
 
...forgot a closing bracket above...

And as another test, this works, too, without createbinary:

Code:
 o.open("POST","[URL unfurl="true"]http://httpbin.org/post")[/URL]
 o.send("test=42")
 do while o.readystate<>4
 doevents force
 enddo
 ? o.responseText

But I doubt this will work with any data and any amount of data. I'd say this is rather just due to a webserver acting graciously with such requests.

Bye, Olaf.
 
Hi Olaf, the last one is the one I'm used to use ( xmlhttp with send([post data] ), with no bin conversion.. I knew the browser control is capable to do post request, but I never used it before. That's why the createbinary made me curious and did some tests like the ones you're posting. Thanks for the advice!
 
Actually I don't find where I read POST data always has to be a binary byte array and in which context, in the context of the HTTP protocol or the xmlhttprequest ole class. I now read in some RFCs the body of the POST containing the post data may just be appropriate to whatever header you set for the content. So to send ascii as "test=42" is also ok for text or other content types, as application/x-
So I learned a new part, too.

Bye, Olaf.
 
Hi All

This thread has been extremely useful for me. One wee tip I found is to include an '&' after the last field in the postdata ie:

lcPostData = "Username=username&Password=password&"


Many thanks to all for a great thread
Jonathan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top