Question
· Dec 24, 2021

How send request without urlencode params in URI?

Hello!

I send request: 

set hr=##class(%Net.HttpRequest).%New()
set hr.Server = "server.com"
set hr.Location = "method?param=value"
do hr.EntityBody.Write("{ "name": "value" }")

set tSC=hr.Send("POST")

But when request incoming to server.com URI = "method
%3Fparam%3Dvalue".
How I can 
disable urlencode params in URI, so that the URI remains "method?param=value"?

Product version: Ensemble 2017.1
Discussion (7)1
Log in or sign up to continue

Oops, instead of hr.SetParam() try hr.InsertFormData("name","value").

This works for me:

USER>set req=##class(%Net.HttpRequest).%New()
USER>set req.Server = "blah.org"
USER>do req.SetParam("name","value")
USER>do req.Post("method",1,0) // 2nd param is output to current device; 3rd is no reset


POST /method?name=value HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; InterSystems IRIS;)
Host: blah.org
Accept-Encoding: gzip
Content-Length: 0
  set hr=##class(%Net.HttpRequest).%New()
  set hr.Server = "server.com"
  set hr.Location = "method"
  do hr.InsertParam("name","value")
  do hr.InsertParam("name2","value2")
  do hr.Post("",1)

And the result

USER>do ^test
POST /method?name=value&name2=value2 HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; InterSystems IRIS;)
Host: server.com
Accept-Encoding: gzip
Content-Length: 0

Jeffrey
USER>do req.Post("method",1,0) // 2nd param is output to current device; 3rd is no reset

Dmitry
do hr.Post("",1)

This parameter of the method was not enough for me for testing, I did not think of using it because of my little experience.

Thank you very much!

And the parameters in the Location property are really urlencode by default (%Net.HttpRequest):

Property Location As %String; Method LocationSet(val As %String) As %Status [ Internal ]
{
  Set i%Location=$zconvert(val,"O","URL")
  Quit $$$OK
}