Hi guys i'am new working with curl, I've already played with wget but never with curl.
My problem is i want to download a csv from a url with GET params but when i do the request curl goes to infinite loop and doesn't do anything and doesn't give any error.
curl --verbose -X 136.17.0.23:83 -U myProxyUser:myProxyPassword -u myHttpUser:myHttpPassword -o C:\outfile "http://136.16.120.13/webtrac/universal_ajax.aspx?tableIdx=54&mode=export&filters=%%22groupOp%%22:%%22AND%%22,%%22rules%%22:\\[{%%22fnield%%22:%%22Year%%22,%%22op%%22:%%22bw%%22,%%22data%%22:%%222014%%22}\\]}&selection="
Related
I have the following batch file that is executing cURL POST command:
curl -i -X POST -H "Content-Type: application/json" -d "{\"text\": \"Hello:\"}" https://xxx
exit
Then I exec the code with windows command, It's work. But if I tried with the same code on a bat file, It didn't work at all.
I thing it could be the "\" ?
Tks for your help.
I’m trying to fill out web forms using curl via a bash script to a website that uses AngularJS. Can’t find any documentation on how to do this. Is it even possible to use curl to POST data to webforms that use AngularJS? I’m not even sure I’m asking the right question or if there’s a better method?
In most cases AngularJS uses ajax calls with JSON payload instead of old-school multipart POSTs.
You can use browser to send test post and save request information "as cURL".
Most likely you will have ready-to-use command to add to your bash file.
But quite often such posts are associated with authenticated person so you will need to fill in up-to-date session cookie into your request.
First things to check will be whether your command works with cleaned cookies.
If it works then your task is done.
Just call such API with something like this:
curl -X POST -H "Content-Type:application/json" \
http://some-server/handle-form \
-d '{"parameter1":["41","34"],"another_parameter":"val1"}'
But if your curl request is rejected by server with cookies absent then you need to setup proper cookie before invocation of API request.
This call will authenticate you against server and will store session cookie in a jar file:
curl -b ./jar -c ./jar -i -X POST -H "Content-Type:application/json" \
http://some-server/login \
-d '{"login":"my-user-name", "password":"my-password"}'
And such save session cookies would be reused for subsequent API calls:
curl -b ./jar -c ./jar -i -X POST -H "Content-Type:application/json" \
http://some-server/handle-form \
-d '{"parameter1":["41","34"],"another_parameter":"val1"}'
I have a few versions of my code in JFROG, which are provided to the clients. How do I specify a generic way to pull latest version(Artifact)? It is not Maven code. I looked up on the Jfrog page:
'''
GET http://localhost:8081/artifactory/ivy-local/org/acme/[RELEASE]/acme-[RELEASE].jar
'''
How do I get [RELEASE] ?
Please help ?
the [RELEASE] in this case is the version number you want to download the latest artifact for. To get that number you can use the REST API call for Artifact Latest Version Search Based on Layout. For example
GET /api/search/latestVersion?g=org.acme&a=artifact&repos=libs-snapshot-local
This would return a string of the latest release version you have.
You can follow the documentation at jfrog
#!/bin/bash
# Note that we don't enable the 'e' option, which would cause the script to
# immediately exit
set -uo pipefail
HOST=myartcloud.jfrog.io
USER=thisIsMyUser
PASS=thisismypass
SNAPSHOT_LAST_VERSION=$(curl --silent --show-error --fail \
-u$USER:"$PASS" \
-X POST https://$HOST/artifactory/api/search/aql \
-H "content-type: text/plain" \
-d 'items.find({ "repo": {"$eq":"my-repo-snapshot"}, "name": {"$match" : "my-project-package-name*"}})'\
| grep -E -o -e 'my-project-package-name-[[:digit:]].[[:digit:]].[[:digit:]]+'| uniq | sort | tail -1 \
| grep -E -o -e '[[:digit:]].[[:digit:]].[[:digit:]]+')
Explanation. Making usage of curl with option
--fail (HTTP) Fail silently (no output at all) on server errors. This is mostly done to better enable scripts etc to better deal with failed attempts.
--silent Silent or quiet mode. Don't show progress meter or error messages. Makes Curl mute.
--show-error When used with -s it makes curl show an error message if it fails.
Then a post request -X POST is made using basic authentication to the api path. The content type of the request is -H "content-type: text/plain".
-d, --data (HTTP) Sends the specified data in a POST request to the HTTP server, in the same way that a browser does when a user has filled in an HTML.
The data sent, is using a filter query to find an repository and also the content.
After the api results, using grep command line utility where it searches for PATTERNS and return only the version number.
Example: 0.1.1
I am trying to create a database with curl from the command line on Windows using this command:
curl -X PUT http://127.0.0.1:5984/test_database.
I receive this response:
curl: (52) Empty reply from server
I am able to see all the created databases (curl -X GET http://127.0.0.1:5984/_all_dbs) and i can also use GET to see information for a specific database created from Futon interface, but PUT doesn't seem to work.
I have also tried to enter the curl command from win-bash command line. I got the same response.
What else should i try?
Is there anyway to use the curl command to update the solr with all the files under a directory? For example like update all the XML files:
curl "http://localhost:8983/solr/xml/update?commit=true&tr=add.xsl" -H "Content-Type: text/xml" --data-binary #*.xml
Using the post.jar, I was able to run these updates, but I am not looking the same function on using CURL ?
Thanks in advance.
I don't think CURL supports making wildcard posts through --data-binary. It does support some globbing in its -T parameter, but that issues a PUT (as it uses the baseurl + filename). You'll also have to expand the list yourself, as I couldn't get * to work as globbing pattern.
The easiest way is probably to wrap it in a for-loop instead, which will depend on how you're running curl (and what OS or shell you're using).
#!/usr/bin/env bash
for FILE in *.xml
do
curl "http://localhost:8983/solr/xml/update?commit=true&tr=add.xsl" -H "Content-Type: text/xml" --data-binary #$FILE
done