curl command - could not resolve xn--x-5gn/post on Ubuntu - node.js

I am using curl command to call rest api. I want to post data and my curl command looks like:
curl –x POST -u 'username:PW' -k -H "Content-Type:application/json" -d '{"json-input":{"handler":"getContent","image":true,"video":false,"text":false,"source":"1","lage":"testlage1"}}' -i http://localhost:8080/com.knime.enterprise.server/rest/v4/jobs/3fd2ca61-c173-4160-a20d-45c387f65f64
I am getting following message:
curl: (6) Could not resolve host: xn--x-5gn curl: (6) Could not
resolve host: POST

The letter before X is wrong. It is supposed to be an ascii minus ('-', ascii code 0x2d / 45) and not the unicode dash character (U+2013) as used in the question.
curl will treat all options that don't start with a minus as a URL, which makes it convert the dash-X string to a IDN hostname and try it. It then continues to try the "POST" host name as that follows the dash-X... None of those host names can be resolved, which is the curl error messages you see.
Then finally: don't use -X POST when you do a post with -d (or with -F)! Just remove the -X POST entirely and things will work better.

check the codepage settings of the terminal software in use and compare these to the host settings
in our case we saw the same strange hostname error returned to a simple
curl -v http://{hostname}:{port}
we discovered the problem was the dash character; the codepage specified in Putty was not consistent with the codepage used at the host so curl treated the -v expression as the hostname.

Related

Getting this error: curl: (3) Host name ' --url' contains bad letter

I am trying to run this line on a linux machine:
curl --request GET \ --url 'https://www.tenable.com/downloads/api/v2/pages/nessus/files/Nessus-10.4.2-ubuntu1404_amd64.deb' \ --output 'nessus.deb'
but I am getting this error:
curl: (3) Host name ' --url' contains bad letter
Warning: Binary output can mess up your terminal. Use "--output -" to tell
Warning: curl to output it to your terminal anyway, or consider "--output
Warning: " to save to a file.
I ended up using: wget https://www.tenable.com/downloads/api/v2/pages/nessus/files/Nessus-10.4.2-ubuntu1404_amd64.deb
but it seems I should not have done it this way because now the subsequent line I want to run isn't working: dpkg -i nessus.deb
The output for the curl was 'nessus.deb'. So to install you had to use 'dpkg -i nessus.deb'.
However, because you used wget, it did not create the output name, but just saved 'INSERTFILENAMEHERE'. So to install it, you would use:
'dpkg -i *INSERTFILENAMEHERE*'
For example, you would have put in
'wget https://www.tenable.com/downloads/api/v2/pages/nessus/files/Nessus-10.4.2-ubuntu1404_amd64.deb'
Then it would say something like
''Nessus.deb' saved'
So you would then put in.
'dpkg -i Nessus.deb'
And it would install the package. In short, the reason why the line was not working was because the file was there, but the name did not match.

Run query API in curl

I'm trying to explore the curl connect or retrieve the data with query API link but when I run my GET command in curl it runs without any error shown in -vv but the process stop. below the actual statement at the end of the posted process, may I know if this is normal or I need to add an additional arguments or parameters on my command for me to retrieve the data? If yes may I know how to do it?
Connection #1 to host myserver.com left intact
My command
curl -vv -k -X GET -H --user user123:password1 -H "Accept: application/json" https://myapplink/statement/EXE=sample

URL encoding with SharePoint URL and cURL

I am new to using CURL. I am trying to connect to a SharePoint URL and pull the data in the form of json. My URL looks like this:
.../_api/web/lists/GetByTitle('titles list')/items
If I give the URL as it is without any encoding, it fails with a HTTP/1.1 400 Bad Request error.
I tried using -G and --data-urlencode like below:
curl -v -G -L --ntlm --user user:password -H 'Accept: application/json;odata=verbose' ".../_api/web/lists/GetByTitle" --data-urlencode "('titles list')" -d "/items"
doing this will convert my URL to .../_api/web/lists/GetByTitle?%28%27titles%20list%27%29&/items
But it fails with HTTP/1.1 404 Not Found since using -G will append to the URL with a ? and & . Putting ? and & to append to the URL will give me a different URL and hence the 404 not found error.
I have no issues accessing other end points like ../_api/web/lists since there is no need to encode it I guess.
How do I properly encode my URL and get the data without any errors?
Any help would be appreciated. Thank you.
I was able to solve the issue by directly giving URL with the encoded characters to cURL command. Like this:
curl -v -L --ntlm --user user:password -H 'Accept: application/json;odata=verbose' ".../_api/web/lists/GetByTitle%28%27titles%20List%27%29/items"
I hope this helps someone. I know I am no expert with linux or cURL and any better answers to this are welcome.

cURL not sending file data

I have a cURL call that I'm trying to use to send file data to a remote server.
curl -X POST -u username:password -d 'data=#/path/to/file.ext&version=2&action=Parse' http://fqdn.to.server.i.control/Parser.cgi
curl -X POST -u username:password -d 'data=#localFile.ext&version=2&action=Parse' http://fqdn.to.server.i.control/Parser.cgi
cat file.ext | curl -X POST -u username:password -d 'data=#-&version=2&action=Parse' http://fqdn.to.server.i.control/Parser.cgi
The file contents are URI encoded already. Using Perl and CGI on the server side.
My problem is that when the server tries to access that "data" line, value I have is only "file.ext" - the path is stripped out and the file's contents are not used ($cgi->param("data") is just "file.ext", "localFile.ext" or "-" respectively).
Any indication as to what I'm doing wrong?
#MattJacob was correct; my syntax was wrong. data=#... should have been #... and the data= portion should have been in the file. Boy am I thick.

Windows Variant of the following Linux code

The Following code is working on Linux but with windows bat file it throws an error :
curl -X PUT --anyauth -u admin:admin --header "Content-Type:application/json" -d {"range-element-index":[{"scalar-type":"string", "namespace-uri":"", "localname":"userName", "collation":"http://marklogic.com/collation/codepoint", "range-value-positions":true,"invalid-values":"reject"}]} http://localhost:8002/manage/v2/databases/db/properties
and the error is as follows :
curl: (6) Could not resolve host: namespace-uri
curl: (6) Could not resolve host: localname
curl: (6) Could not resolve host: collation:http
curl: (3) [globbing] unmatched close brace/bracket in column 49
{"errorResponse":{"statusCode":"400", "status":"Bad Request", "messageCode":"XDMP-JSONCHAR", "message":"XDMP-JSONCHAR: xdmp:unquote(\"{range-element-index:[{scalar-type:string,\", (), \"format-json\") -- Unexpected character 's' in JSON at line 1 char 36"}}
Indeed, the issue is likely the fact that the rest payload needs to be quoted.
There are various places in the ML guides that show windows versions of commands (such as for MLCP).
As an example of your challenge - and what looks like the solution, please see the conversation at the bottom of this page - including screen-shots of a cUrl command on windows:
https://developer.marklogic.com/learn/rest/setup

Resources