Forum OpenACS Development: [ns_http run] return http0

Request notifications

Collapse
Posted by Iuri Sampaio on
Wrapping up headers and JSON content, to POST against Sendgrid's API, I noticed that it returns http0, while I was expecting to see a JSON result.

[09/Nov/2018:17:55:20][2622.7fa7b08ef700][-conn:evex:1:84-] Notice: http0

The source code is:

###
#set http [util::http::get -url $url] Bad call ad_proc deprecated
# is ad_proc util::http::post deprecated?

set content [export_vars $url]
set req_hdrs [ns_set create]

# headers necesary for a post and the form variables
ns_set put $req_hdrs Accept "*/*"
ns_set put $req_hdrs User-Agent "[ns_info name]-Tcl/[ns_info version]"
ns_set put $req_hdrs "Content-Type" "application/json"
ns_set put $req_hdrs "Content-Length" [string length $content]
ns_set put $req_hdrs "authorization" "Bearer XXXXX"

...

set body "
{"personalizations":[{"to":[{"email":"mailto:iuri.sampaio@gmail.com","name":"Iuri Sampaio"}],"subject":"Hello, World frmo Sendgrid!"}], "template_id":"d-0e5333876a1f4676b2dd16f2587e7380","content": [{"type"\
: "text/plain", "value": "Heya!"}],"from":{"email":"mailto:noreply@evex.co","name":"EvEx"},"reply_to":{"email":"mailto:noreply@evex.co","name":"EvEx Evento Exp
erience"}}
"

# POST Request

set http [ns_http run -method "POST" -headers $req_hdrs -body $body $url]
ns_log Notice "$http"

Best wishes,
I

Collapse
Posted by Gustaf Neumann on
What you see is the expected result in versions of NaviServer up to NaviServer 4.99.16. In these versions, you should be able to "... -result varName ..." to get the body into a variable named "varName".

This behavior has changed in NaviServer 4.99.17 (see [1]).

[1] https://bitbucket.org/naviserver/naviserver/src/12b3f7e266d36d1dd8313cf3dc036d1f8da9c5bc/NEWS#lines-77

Collapse
Posted by Iuri Sampaio on
Hi Gustaf,
I was drinking directly from the source: https://naviserver.sourceforge.io/n/naviserver/files/ns_http.html

and indeed I'm running release 4.99.16 still.

The call to [ns_http run] was wrapped in a TCL variable, as in:

set http [ns_http run -method "POST" -headers $req_hdrs -body $body $url]

However, even when I change as you corrected myself, it complains about the new switch i.e. -result

ns_http run -method "POST" -headers $req_hdrs -body $body -result http $url

I'm going to try [ns_http wait] and more derivations.

[10/Nov/2018:13:03:57][4766.7f235e7fc700][-conn:evex:25:25490-] Error: wrong # args: should be "ns_http run ?-body body? ?-body_file body_file? ?-cafile cafile? ?-capath capath? ?-cert cert? ?-headers headers? ?-hostname hostname? ?-keep_host_header? ?-method method? ?-timeout timeout? ?-verify verify? url"
while executing
"ns_http run -method "POST" -headers $req_hdrs -body $body -result http $url"
("uplevel" body line 36)
invoked from within
"uplevel {
ad_page_contract {}

auth::require_login

# Gets user's current location
set p

Collapse
Posted by Iuri Sampaio on
... or I could easily upgrade NS to .17.

Is https://github.com/gustafn/install-ns already on 4.99.17?

Collapse
Posted by Iuri Sampaio on
That's it. Upgrade scripts ran nice and easy. I'm on 4.99.17 and [ns_http run] runs smoothly!
Collapse
Posted by Gustaf Neumann on
Keep in mind, that the documentation on sourceforge corresponds always with the newest released version at sourceforge...