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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using WestWind wwwipstuff to post form data...

Status
Not open for further replies.

GriffMG

Programmer
Mar 4, 2002
6,288
1
38
FR
I suspect that someone red flagged an earlier thread asking for a consultant to help with the above.

Now, that falls outside the posting guidelines, and reporting it was certainly justified, but as I had
answered the query with a simple example that has gone at the same time, I thought I would post the code again.

Firstly you need to include the wwhttp.prg in your project and call it before you use the classes contained
in wwipstuff.vcx (which also needs to be included in your project).

Then you can do this:

Code:
DO WWHTTP
OHTTP = CREATEOBJECT("wwHTTP")
*** Set mode to multi-part form
OHTTP.NHTTPPOSTMODE = 2
OHTTP.ADDPOSTKEY("Project","The name of my project")
LCHTML = OHTTP.HTTPGET("[URL unfurl="true"]http://www.myserver.com/myaspfile.asp")[/URL]
RELEASE OHTTP


I have used a classic asp reference as the target for the post, but it could be
aspx or php or whatever, to access the result ("Project" in this case) in asp
you need code like this in the file.

Code:
strProject 				= Request.Form("Project")

But watch out how you use that received string, it might be a SQL injection vector, so
apply it using a parameterized query (so it can't be executed) or run it through something
that would remove anything 'dangerous' like "drop table tblUsers" B-)


Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

There is no place like G28 X0 Y0 Z0
 
I suspect that someone red flagged an earlier thread asking for a consultant to help with the above.

Yes, that would have been me (and possibly others as well). As you pointed out, Griff, that post contravened the forum guidelines; it also included the poster's email address, which is not allowed in the forum.

It's a pity that deleting the post meant that your reply was also lost, but it's good that you have taken the trouble to re-post. No doubt others will find this useful.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I just wonder about using HTTPGET for posting, is it just a general name for requests and whether it's GET or POST depends on NHTTPPOSTMODE mode?

What version of wwHTTP is this?

The documentation I find online makes a step before first instanciation of the wwHTTP class, calling a wwHTTP.PRG, taken from
Code:
DO wwHttp
LOCAL loHttp as wwHttp OF wwhttp.prg
loHttp = CREATEOBJECT("wwHttp")

*** Post HTML Form Variables
* loHttp.cContentType="application/x-[URL unfurl="true"]www-form-urlencoded"[/URL]  && default for POST
loHttp.AddPostKey("Name","Rick")
loHttp.AddPostKey("Value","1")
lcHTML = loHttp.Post("[URL unfurl="true"]https://yoursite.com/some/endpoint")[/URL]

*** POST a JSON request to a server
lcJson = [{"name": "Rick", "company": "West Wind", "entered": "2020-10-21T08:12:33Z"}]

*** Recreate wwHttp (best practice)
loHttp = CREATEOBJECT("wwHttp")

*** Post a raw Buffer of data
loHttp.cContentType="application/json"
lcHTML = loHttp.Post("[URL unfurl="true"]https://yoursite.com/some/json/endpoint",[/URL] lcJson)

Notice this code shows several use case scenarios, not just one.



Chriss
 
Get and post seem to both be performed by httpget... I took the example for a long term working project, so I hope so. B-)

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

There is no place like G28 X0 Y0 Z0
 
Griff,

we may just talk about vocabulary here, but the major problem I see with your tip is that only people with an older version of wwHTTP can use it.
So let me check this first.

I downloaded wwHTPP as embedded in which contains a wwhttp.prg.

Your code works and does a POST request. May be fine, but I don't see it being as concise about the POST operation.
The NHTTPPOSTMODE = 2 you pick, in detail turns out to do a Content-Type: multipart/form-data request, application/x- may be needed.

In the end you don't get around to have the detail knowledge about which content-type header to use to bring over form data and not just a raw POST the server side doesn't understand.

I think the sample code of wwHTTP is cleaner on the aspect of making a POST request and I'd prefer it.

Chriss
 
Sorry Chris, I agree, would be nice if I had a more up to date version... but we work with what we have
rather than what we would like to have. B-)



Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

There is no place like G28 X0 Y0 Z0
 
Griff, notice that novice users, who you want to give that advice, would likely work with the latest version.

Chriss
 
Well they might, but as you said the code example - written for an aged version - works just fine with a more recent version...


Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

There is no place like G28 X0 Y0 Z0
 
Well, you're still throwing out a more clearer variant of what the code actually does.

A POST is never a GET and that HTTPGet can be used to make POST request is a design flaw on the level of naming.

In the description of AddPostKey I find a remark:

West Wind said:
* Note: Prior to v7 you can use .HttpGet() instead of .Post() or .Put()
Seems you still can, but I guess mainly only for backward compatibility.

If you single step through what wwipstuff does, I can tell it does a lot of things you don't automatically get done and considered using just WiniNet or the XMLHttpRequest OLE classes you may also use in VFP, but Ricks naming gets even weirder as a method called HttpGetEx is called.

Chriss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top