1

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?

1
  • AngularJS is a front-end framework. It sends HTTP requests to a backend, jus as curl does. What you need is the documentation of the backend HTTP API that AngularJS sends requests to. Commented Dec 25, 2019 at 7:48

1 Answer 1

1

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". enter image description here

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"}'
Sign up to request clarification or add additional context in comments.

2 Comments

Awesome post! I haven’t used JSON before—I’ll have to do some reading on it. I know the forms are complex and have drop down menus and file uploads for .mp3 files. Does JSON handle all that as well?
"using-curl-with-angularjs" - is this page at StackOverflow. I used it to make screenshot. your request will certainly have some other name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.