I started to play with nim today. I'm trying to port very simple utility written in "another programming language". The utility should do few http request and parse resulting xml/json but when I try to use httpclient I get Error: unhandled exception: 406 Not Acceptable [HttpRequestError]
I've compared headers with working curl ones and they both look pretty identical:
curl sends:
nc: using stream socket
GET //api/request/0123251 HTTP/1.1
Host: localhost
User-Agent: curl/7.42.1
Accept: application/xml
Authorization: Basic <hash_here>
nim utility sends:
nc: using stream socket
GET //api/request/0123251 HTTP/1.1
Host: localhost
User-Agent: Nim httpclient/0.1 ## I've tested with curl/7.42.1 with no success
Accept: application/xml
Authorization: Basic <hash_here>
Any ideas how to debug this further?
We need some more information to diagnose this.
What are you expecting to get from the server? (what's the full curl output)?
Could you give me a URL to this server? Some code?
Which version of Nim are you using?
I cannot provide with URL. It's corporate server with authentification and sensitive information. Sorry :( I'm going to test the code with ovirt REST API as far as it uses the same approach/headers and will provide you with access if it fails.
Server returns back XML (or JSON if application/json was specified). It's REST. XML looks like
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><request>
<submitter>name</submitter>
<text>.....</text>
</request>
Code (draft) looks like:
from httpclient import getContent
from base64 import encode
## Extra headers can be specified and must be separated by \c\L
var headers = ""
discard """
headers = {"Content-Type": "application/xml",
"Accept": "application/xml",
"Accept-Charset": "utf-8",
"Authorization" : ("Basic %s" % auth)}
"""
const user = "username"
const password = "password"
const authString = user & ":" & password
const auth = encode(authString, lineLen=1024)
## Headers commected out during debugging
##headers = headers & "\"Content-Type:\" : \"application/xml\" \c\L"
##headers = headers & "\"Accept\" : \"application/xml\" \c\L"
##headers = headers & "Accept-Charset: utf-8 \c\L"
headers = headers & "Accept: application/xml\c\L"
headers = headers & "Authorization: Basic " & auth & "\c\L"
echo(headers)
echo(getContent("https://api.server.name/api/request/0123251", extraHeaders = headers, userAgent = "curl/7.42.1"))
Authorization works fine (not getting 401) so server understand "Auth" header at least.