wwHTTP::AddPostKey

Set POST data to send on a POST or PUT request.

This method sets the post buffer and supports encoding for HTML form based uploads as well as raw data buffers.

Several different mechanisms are available:

  • UrlEncoded Form Data nHttpPostMode=1
  • Multi-Part Forms nHttpPostMode=1
  • Raw Data cContentType="application/json"

The two HTTP Form post modes - UrlEncoded and Multi-Part are supported via the nHttpPostMode flag which triggers specific content encoding of the key value pairs passed.

For raw Data content like JSON, XML, or binary data you pass the data in tcKey and set the cContentType property with the data's content type.

For HTTP File Upload form keys using multi-part forms, please use the AddPostFile() method.

Note: For raw data requests you can also pass the POST data directly on the .PostMethod() instead of using .AddPostKey().

o.AddPostKey(tcKey, tcValue)

Return Value

nothing

Parameters

tcKey
The key of the value to set or if tcValue is not passed, the entire raw POST buffer to send.

If no parameters are passed the entire PostBuffer is cleared.

tcValue
The value to set the key to. In combination these values are equivalent to a Form Variable name and value.

Multi-Part Forms specific parameters

Remarks

UrlEncoded content that is longer than 254 characters requires wwIPStuff.dll for the URLEncoding using C++ code for better performance. This refers to the default nHttpPostMode value of 1.

Depending on the value of the nHTTPPostMode property forms are posted either in standard URLEncoded or Multi-Part form mode. Multi-part form mode can be more efficient for large uploads as no encoding takes place, but the server application must support parsing multi-part forms. Web Connection automatically handles this via Request.Form().

Example

loHTTP = CREATEOBJECT("wwHTTP")

*** Standard HTML style UrlEncoded Form Variables
loHTTP.AddPostKey("Company","West Wind")
loHTTP.AddPostKey("Name","Rick Strahl")

lcHTML = loHTTP.Post("http://www.west-wind.com/wconnect/testpage.wwd")

*** Posting JSON
loHTTP.AddPostKey()  && Clear POST buffer
lcJson = FILETOSTR("someJsonData.json")

*** Raw post buffer
loHTTP.cContentType = "application/json"
loHTTP.AddPostKey(lcJson)   && Just the raw data, no key

lcJson = loHTTP.Post("http://www.west-wind.com/wconnect/testJson.wwd")

*** Posting a multi-part form with a File Upload
loHTTP.AddPostKey()  && Clear existing POST buffer

loHTTP.nHttpPostMode = 2  && Multipart form encoding

*** Post a file and a regular form variable
loHttp.AddPostFile("File","d:\temp\wws_invoice.pdf",.T.)
loHttp.AddPostKey("txtFileNotes","test note")

lcHTML = loHTTP.Post("http://localhost/wconnect/FileUpload.wwd")

See also:

Class wwHttp | wwHTTP::nhttppostmode |

© West Wind Technologies, 1996-2020 • Updated: 10/23/20
Comment or report problem with topic