wwHTTP::nHttpPostMode

Sets the form POST mode for requests specifically for key value pair form submissions that use AddPostKey(lcKey, lcValue). This property only applies to Url Encoded (application/x-www-form-urlencoded) or Multi-Part (multipart/form-data) form data not to full document types like application/json or text/xml for example.

For any other full document content type operations that use AddPostKey(lcValue) - like application/json or text/xml - set the cContentType property instead.

Do not use both nHttpPostMode and cContentType - use one or the other.

Available form post modes for key value data are:

Value Description Content Type
1* Form Url Encoded (typical POST) application/x-www-form-urlencoded
2 Multipart forms (file uploads) multipart/form-data

These settings apply only for calls to AddPostKey(key, value) when key and value parameters are passed. These key value pairs are then appended into the POST buffer that is built up with each call to AddPostKey(key,value).

For all other raw buffer data like JSON or XML or binary files passed use the cContentType Property instead.

Form POST Value Encodings

Url Encoded Form
application/x-www-form-urlencoded
Url encoded uses key value pairs as Url Encoded content which looks like this as a POST buffer:

name=Rick%20Strahl&company=West%20Technologies

It's the equivalent of an HTML form that submits with:

<form action="http://localhost:8000" method="post">

Multi-Part Form (application/x-url-encoded)
multipart/form-data
Multipart forms are generally used for file uploads or other binary data to post from HTML forms. It tends to be more efficient than Url Encoded, because the actual data is not encoded and sent raw. Instead every variable has a MIME header that describes the content. Each content block is raw text or binary data.

----------------------------9051914041544843365972754266
Content-Disposition: form-data; name="text"

text default
-----------------------------9051914041544843365972754266
Content-Disposition: form-data; name="file1"; filename="a.txt"
Content-Type: text/plain

Content of a.txt.

-----------------------------9051914041544843365972754266
Content-Disposition: form-data; name="file2"; filename="a.html"
Content-Type: text/html

<!DOCTYPE html><title>Content of a.html.</title>

It's equivalent to form submission from an HTML form:

<form action="http://localhost:8000" method="post" enctype="multipart/form-data">

Only use for Key Value Pair POST data

nHttpPostMode=2 or nHttpPostMode=4 are meant for the specific use case of send HTML style form data using key value pairs using AddPostKey(key,value) append to the post data already present in the buffer.

For any other content types or full 'documents' of data **always use the cContentType property instead.

Default Mode

If neither nHttpPostMode or cContentType are set, the default POST mode is nHttpPostMode=2 which is url encoded form data with a content type of application/x-www-form-urlencoded.

Remarks

Only set for key, value pair operations of Url Encoded or Multi-Part form data using AddPostkey(key, value).

For all other document types that AddPostkey(value)

This property has to be set prior to calling AddPostKey().

Example

*** POST to a standard HTML form
loHttp = CREATEOBJECT("wwHttp")

loHttp.nHttpPostMode = 1  && UrlEncode form vars
loHttp.AddPostKey("userid","43zaas1")
loHttp.AddPostKey("password","seekrit332")

lcHtml = loHttp.Post("http://somesite.com/loginform.wcsx")

*** Post to a multi-part form that includes a file (file upload)
loHttp = CREATEOBJECT("wwHttp")
loHttp.nHttpPostMode = 2  && multi-part / file

*** Upload a file
loHttp.AddPostKey("image","c:\temp\sailbig.jpg",.T.)
loHttp.AddPostKey("notes","sailing the seas of cheese")

lcHtml = loHttp.Post("http://somesite.com/uploadform.wcsx")


*** Post a JSON document - using cContentType instead of nHttpPostMode
loHttp = CREATEOBJECT("wwHttp")
loHttp.cContentType = "application/json"
loHttp.AddPostKey([{ name: "Rick Strahl", company: "West Wind" }])
lcJson = loHttp.Post("http://somesite.com/uploadJson.wcsx")

See also:

West Wind Web Connection | wwHTTP::AddPostFile | wwHttp::cContentType

© West Wind Technologies, 2023 • Updated: 06/07/20
Comment or report problem with topic