Question
· 11 hr ago

Sending HTTP Request as an application/x-www-form-urlencoded

In my previous HttpRequests, I have used Content-Type = application/json but I have a vendor that is requesting we send application/x-www-form-urlencoded. How would I go about formatting the Payload as x-www-form-urlencoded?

Thanks

Product version: IRIS 2024.2
$ZV: HealthShare Provider Directory 2024.2.0 Build: 1009 [HealthShare Modules: Core:28.0 + Provider Directory:28.0] - IRIS for UNIX (Red Hat Enterprise Linux 8 for x86-64) 2024.1 (Build 267_2_24113U) Wed Jul 2 2025 16:36:55 EDT [Core:28.0|Provider Directory:2
Discussion (1)2
Log in or sign up to continue

To send an HTTP request using the Content-Type: application/x-www-form-urlencoded, you can use the %Net.HttpRequest class in ObjectScript. Below is an example of how to create and configure the request:

  1. Create an instance of %Net.HttpRequest.
  2. Set the required properties, such as Server, Port, and Https.
  3. Set the ContentType to "application/x-www-form-urlencoded".
  4. Add form data to the request using the InsertFormData method.
  5. Call the Post method to send the request.

Here is an example ObjectScript code:

Set httpRequest = ##class(%Net.HttpRequest).%New()
Set httpRequest.Server = "your.server.com"
Set httpRequest.Port = 443
Set httpRequest.Https = 1
Set httpRequest.ContentType = "application/x-www-form-urlencoded"
Set httpRequest.ContentCharset = "utf-8"

// Add form data
Do httpRequest.InsertFormData("key1", "value1")
Do httpRequest.InsertFormData("key2", "value2")

// Send the POST request
Set sc = httpRequest.Post("/your/endpoint")

// Check the response
If sc $$$ISOK {
    Write httpRequest.HttpResponse.Data.Read()
} Else {
    Write "Error: ", sc
}

Make sure to replace placeholders like "your.server.com" and the endpoint with actual values. In the example, form key-value pairs are added with the InsertFormData method [1][2].

Sources: