Dear Iuri,

Let's start with a simple example: make a GET request to a service, which
requires basic authentication

  % ns_http run https://jigsaw.w3.org/HTTP/Basic/

status 401 time 0:513863 headers d11 body {<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 
4.01 Transitional//EN"
               "http://www.w3.org/TR/html4/loose.dtd";>
<html>
<head>
...


NaviServer returns (starting with 4.99.17) for "ns_http run" a Tcl dict with
the relevant information. The request above returns the HTTP status
code 401, which means "Unauthorized".

Ok, now add some Authorization. As defined by RFC 7617, one has to add an
Authorization request header field with user:id:password encoded in base64.

  % set h [ns_set create]
  % ns_set update $h Authorization "Basic [ns_base64encode guest:guest]"
  % ns_http run -headers $h https://jigsaw.w3.org/HTTP/Basic/

status 200 time 0:485802 headers d8 body {<!DOCTYPE HTML PUBLIC "-//IETF//DTD 
HTML//EN">
<html>
  <head>
...


Now we see the status code 200, which means that the Authentication was ok.
If you still get a status code of 401, probably userid and/or password are not ok.

Hope this helps.
-gn

On 15.11.19 16:21, Iuri Sampaio wrote:
What would be the argument/switch to convert the option -u, from CURL command, to ns_http command?

|curl -v https://myhost.com/oauth2/token <https://myhost.com/oauth2/token> \ -H "Accept: application/json" \ -H "Accept-Language: en_US" \ -u "client_id:secret" \ -d "grant_type=client_credentials"|

_______________________________________________
naviserver-devel mailing list
naviserver-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/naviserver-devel

Reply via email to