I am a noob at all this and I am trying to run a Linux curl command in Windows 10 to generate session key. The following is the command in Linux.
curl -H "Content-Type: application/json" -d '{"id":1, "jsonrpc":"2.0", "method": "author_rotateKeys"}' http://localhost:9933/
When I run the command at the Windows command prompt I am receiving the following error.
E:\>curl -H "Content-Type: application/json" -d '{"id":1, "jsonrpc":"2.0", "method": "author_rotateKeys"}' http://localhost:9933/
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) unmatched close brace/bracket in URL position 18:
author_rotateKeys}'
^
E:\>
Any idea how would I covert the command to work with Windows 10? I just need to generate a key for a node I need to connect to from a Windows box.
If you don't have WSL2 setup (useful if you ever need other *nix tools) where that command will just work as is, or don't want to use PowerShell where
curl.exe -H "Content-Type: application/json" -d '{"id":1, "jsonrpc":"2.0", "method": "author_rotateKeys"}' http://localhost:9933/
works (notice the curl is replaced with curl.exe, because in PowerShell 5.1 curl is just an alias for Invoke-WebRequest, it's removed in PowerShell 6 and later, but they're not built-in and won't replace PowerShell 5.1 when installed), then on Command Prompt replace single quote with double quote, and for double quote inside them, escape it (replace it with \")
curl -H "Content-Type: application/json" -d "{\"id\":1, \"jsonrpc\":\"2.0\", \"method\": \"author_rotateKeys\"}" http://localhost:9933/
Related
I'm running Jenkins pipeline job on a windows 10 agent.
i'm trying to publish some information from the agent to confluence.
Running with script.bat:
curl --fail --silent --show-error -u ****:**** -X GET <SomeInternalAddress>
works!
but running:
curl --fail --silent --show-error -u ****:**** -X POST -H 'Content-Type: application/json' -d '#tmpCurlPostData.txt' <SomeInternalAddress>
results with:
curl: (6) Could not resolve host: application
curl: (22) The requested URL returned error: 415
tried escape a '=' in the password with '^'. tried surrounding with quotes.
but with no success.
interesting fact, the same code works fine on win 7,
testing it on a new win 10 machine revealed the problem.
would appreciate any idea guys.
thanks a lot!
I am using the following command to upload file to an endpoint
curl -X POST -H "authorization: Basic base64encode" -H "Content-Type:
multipart/form-data" -H "X-Atlassian-Token: nocheck" -F
"file=#c:/Users/User/Desktop/testresults.xml" https://jira.test-
server.ag/rest/api/latest/issue/man-287/attachments
the command under mac works without problems, under windows I become the following error
curl: (26) read function returned funny value
curl version
curl 7.64.0 (x86_64-w64-mingw32) libcurl/7.64.0 OpenSSL/1.1.1a
installed using https://chocolatey.org
I ran into the same problem when I used curl on the Windows Subsystem for Linux on Windows 10. I had to change the path from C:\Temp\File.txt to /mnt/c/Temp/File.txt.
Check if you can access the file in your shell e.g. with dir c:\path\to\file.txt and if it fails then you know that you have to fix the path first.
I'm using CURL to execute some API calls against a bitbucket server. The command is like this:
curl https://bitbucket.myserver.com/rest/api/1.0/projects/PRJ/repos/repo-slug/tags \
-u 'user:pass' \
-X POST \
-H 'Content-type: application/json' \
-d '{"name" : "test-tag", "message": "Test tag from curl", "startPoint": "master" }'
This is expected to create a tag on the master branch in the repo. This however fails complaining of incorrect username/password.
I then copy/paste the command into git-bash prompt - and it works as expected, completing successfully. I tried this with multiple user accounts. I also tried specifying only the username and then entering the password on command line - with the same results.
How can I get curl on windows to pass correct username/password to the server?
I'm trying to run a curl command from the command line in Windows, but for the life of me I can't figure out how I'm supposed to escape it.
I'm executing this:
C:\WINDOWS\system32>curl --anyauth --user user:password -X POST -d "{\"rest-api\":{\"name\":\"BizSimDebug3\"}}" -H "Content-type: application/xml" http://localhost:8002/v1/rest-apis
And I'm getting this:
<rapi:error xmlns:rapi="http://marklogic.com/rest-api">
<rapi:status-code>400</rapi:status-code>
<rapi:status>Bad Request</rapi:status>
<rapi:message-code>RESTAPI-INVALIDCONTENT</rapi:message-code>
<rapi:message>Your bootstrap payload caused the server to throw an error. Underlying error message: XDMP-DOCROOTTEXT: xdmp:get-request-body() -- Invalid root text "{"rest-api":{"name":"BizSimDebug3"}}" at line 1</rapi:message>
</rapi:error>
Is there something else I need to do to escape the inner quotes in the -d flag? Or am I overlooking the real issue entirely?
This works in Windows:
curl -i -X POST -H "Content-Type: application/json" -d "{\"Field1\": 123, \"Field2\": 456 }" "http://localhost:8080"
The XDMP-DOCROOTTEXT error indicates the server is trying to parse the payload as XML and failing.
The Content-Type header is telling the server that you're sending XML, but the payload is JSON.
Try changing the Content-Type header to application/json
Quoting is hell. By "Windows Command Line and your prompt I presume you mean cmd.com ?. That doest quote the same as linux shells.
For this simplistic experiment I recommend going for 2 kinds of quotes to avoid escaping But even then its unlikely to work
curl --anyauth --user user:password -X POST -d "{'rest-api':{'name':'BizSimDebug3'}}" -H "Content-type: application/xml" http://localhost:8002/v1/rest-apis
Better luck might be had by going with a unix-like shell such as running cygwin (http://www.cygwin.com/) or maybe xmlsh (www.xmlsh.org) which escape like linux does.
You really are going to have a nightmare running anything complex through the windows command line natively.
-David
I need to post XML data via curl.exe under windows using PUT request.
In the curl help I found:
-d/--data <data> HTTP POST data (H)
What should I supply for <data>?
curl sample calls
# with inlining plain data
curl -X PUT -d "payload" http://localhost
# referrring file
curl -X PUT -d #myXmlFile.xml http://localhost
If your windows curl-port does not support it go for cygwin. It is a linux-like environment for windows and also offers "a proper" curl.
In windows, if a double-quoted argument itself contains a double quote character, the double quote must be doubled.
For example, enter 'This is "quoted" payload' as "This is ""quoted"" payload" which is very different than in Unix.
Example:
curl -X PUT -d "This is ""quoted"" payload" http://localhost
in windows you'll need to put the # inside the quotes for the file you're sending:
curl -XPUT --data-binary "#uploadme.txt"
otherwise you'll get weird errors as it tries to use the content of the file as the url:
curl: (6) Couldn't resolve host 'upload'
curl: (6) Couldn't resolve host 'me!'
(uploadme.txt contains "upload me!")
on Windows CMD, curl refers to C:\Windows\System32\curl.exe so you can use
curl -X PUT -d "payload" http://localhost
instead on Windows PowerShell curl refers to Invoke-WebRequest so it is not working with curl syntax. you can use curl.exe on PowerShell to call C:\Windows\System32\curl.exe so it will solve the issue.
curl.exe -X PUT -d "payload" http://localhost