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"}'
Related
I am trying to run a POST call to update dialog node of watson assitant but getting error {"error":"Invalid CSRF Token"}.
my curl command is:
curl -H "Content-Type: application/json" -X POST -u "03abc-6def3-4sds53-9red-394aaaaaaaaaaaae2:passwprd" -d "{\"dialog_node\":\"handler_40_133229823644\",\"type\":\"event_handler\",\"conditions\":\"$version == null\",\"parent\":\"slot_39_1521312319823644\",\"previous_sibling\":\"handler_41_1543623423444\",\"output\":{},\"context\":{\"temp\":\"$version == null\",\"sys_options\":[{\"label\":\"19.5.0\",\"value\":\"1950\"},{\"label\":\"19.2.1\",\"value\":\"1921\"},{\"label\":\"19.2.0\",\"value\":\"1920\"},{\"label\":\"18.11.1\",\"value\":\"1812\"},{\"label\":\"18.11.0\",\"value\":\"1811\"},{\"label\":\"18.8.1\",\"value\":\"1881\"},{\"label\":\"18.8.0\",\"value\":\"1880\"},{\"label\":\"18.5.1\",\"value\":\"1851\"},{\"label\":\"17.5.0\",\"value\":\"1851\"}]},\"actions\":null,\"metadata\":{},\"event_name\":\"input\"}" "https://assistant-us-south.watsonplatform.net/rest/v1/workspaces/adjs42424-73423de-324dd-d397-affasdsade234ad27/dialog_nodes/handler_40_154asdasd823644"
I think you are missing the version in the url. From the API documentation - https://cloud.ibm.com/apidocs/assistant#update-dialog-node it should be something like -
curl -u "apikey:{apikey}" -H "Content-Type: application/json" -X POST -d "{\"output\":{\"generic\":[{\"response_type\":\"text\",\"values\":[{\"text\":\"Hello! What can I do for you?\"}]}]}}" "https://gateway.watsonplatform.net/assistant/api/v1/workspaces/{workspace_id}/dialog_nodes/greeting?version=2019-02-28"
The example doesn't include the dialog node as part of the -d json structure, and makes use of an IAM Key instead of userid / password authentication. Though if your service credentials still are userid / password based they should still work.
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
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
i am trying to make HTPPS request to a server to send json file using curl .
please help me out
I guess your question means "I want to send JSON data to a server with cURL".
curl -H "Content-Type: application/json" -d '{"username":"xyz","password":"xyz"}' http://localhost:3000/api/login
The above example taken from this answer should work. Modify the text after -d accordingly.
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="