I'm new to libcurl but I would like to implement the following curl command using libsoup:
curl --data-binary '#test.mp4' -H "x-file-name:test.mp4" http://server/upload
How can I do the same with libsoup? Could you give me some examples how to upload a big binary file using libsoup?
Related
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 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.
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.
Im trying to use CURL to connect to SOLR db but my curl does not give any response...
curl -X GET 'http://localhost:8983/solr/#/collection1/select?q=*:*'
The web interface works very welll.
You should remove the fragment identifier (hash mark)
curl -X GET 'http://localhost:8983/solr/collection1/select?q=*:*'