wwHTTP::Post

Uses an HTTP POST operation to post content to the Web server and to retrieve Web content from a URL. You can pass in a URL and the raw Post data to send. Make sure to set .cContentType if using non-Html form data.

DO wwHttp
LOCAL loHttp as wwHttp OF wwhttp.prg
loHttp = CREATEOBJECT("wwHttp")

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

*** 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"
lcJsonResult = loHttp.Post("https://yoursite.com/some/json/endpoint", lcJson)

JSON Service Requests using wwJsonServiceClient

If you're sending data to JSON REST Services you can simplify the JSON serialization and HTTP calls using the wwJsonServiceClient class which lets simply pass and receive objects and values rather than serialized strings.

Please also see wwHttp::HttpGet and Access Http Content over the Web

o.Post(lcUrl, lcPostData, lcOutputFile)

Return Value

String - HTTP result, which most likely will be HTML, but can be whatever data the link returns. This includes XML and binary data like Word documents or even data files. On error this string will be blank and the nError and cErrorMsg properties will be set.

Parameters

lcUrl
The full URL you want to retrieve. This URL must include the protocol (HTTP or HTTPS for example) and the Domain Name or IP Address. Example: https://west-wind.com/default.aspx

lcPostBuffer
Optional - Optional raw post buffer to send to the server - overrides any other post data you might have added with AddPostKey(). Make sure you set the .cContentType with the type of the data you are sending like application/json.

lcOutputFile
Optional - A filename into which to download the result content into. This allows you to download large content including greater than 16mb directly into a file. If this parameter is used the return value from this method will always return blank and only the file is created on success. To check for errors, check the nError/cErrorMsg and the cResultCode properties.


See also:

Class wwHTTP | wwHTTP::HTTPGet (deprcated) | Class wwJsonServiceClient

© West Wind Technologies, 1996-2024 • Updated: 03/28/23
Comment or report problem with topic