Login and post using curl in one command - http

I am configuring a solar device on the field that runs a small web server to upload data to a web service.
However the web service needs to have authentication and ssl. There is a way to configure an upload url endpoint but not a way to save the headers to a file etc.
Is it possible to login pass the headers to the next request and post data all in one request?
Something like
curl -d "email=sadf#yahoo.com&password=asds&submit=Login" --dump-header headers http://localhost:3000/users/login **>** curl -X POST http://localhost:3000/test --data-urlencode point="<status>A note</status>" -H 'Content-Type: application/xml'

Related

Creating URL with headers

I can curl a website URL by passing on some header params. I am trying to get the same result on the browser but I cannot build the URL for the browser in the right way.
My curl looks something similar
curl -X GET -u 'xyz#gmail.com' -H "app-key: some-keys" -H "account-email: procurement#gmail.com" -H 'Content-Type: application/json' -d 'paused=false' https://api.pingdom.com/api/2.1/checks
When prompted for the password, i can give the password and Iget the JSON response.
Now I try to build the same URL on my browser. The browser prompts for user name and password which I have already given.
Now my URL looks like this.
https://api.pingdom.com/api/2.1/users?account-email=procurement#gmail.com&app-key=some-key
I get a forbidden (as JSON reponse) when I try from the browser and from Curl I get the proper JSON response.
How can I add header params to a URL when pinging from the browser?
How can I add header params to a URL when pinging from the browser?
That's not possible. Besides it, from the browser address bar you won't be able to use HTTP methods other than GET.
So I advise you to you proper tools to target/test your Web API such as Postman or Paw.

Can not send curl request. Authorization has been denied for this request

I successfully sent request with postman with basic authorization and 1 custom header - token.
Now I need to sent the same request using curl.
This is how postman parameters look like:
And this is my curl command:
curl -k -u my#mail.com:1Qwer432 -H "CERequestToken: 46Yx2fo4t5+p1IX" https://mysite/v54/api/contracts
What am I doing wrong?
I found the solution. The problem is that curl does not save cookies. And it's necessary to send cookies with request.

Request parameters are not passed to the backend service

I configured a REST webservice (a Spring Boot webapplication) on WSO2 AM and used the default /* mapping for resources. My webservice takes an assignee (text) and file parameters.
When I perform the calls, I've noticed that request parameters are not forwarded (HTTP Headers are) to the backed services. For example:
curl -i -X POST -H "Content-Type: multipart/form-data" -H "X-PD20-BillingSubscriptionId: e87d4400-b05f-4f40-9c39-06ae4d28cf4d" -H "Authorization: Bearer rrxRV5F6jdkSBcEPXv7I1yFl2x8a" -F "documentFile=#src/test/resources/sample-files/test-fea-1firma.pdf" -F "assignee=bla.bla#gmail.com" http://api.linksmt.it:8280/fea/1.0.0/signRequest
As you can see, It's a form that posts 2 fields, one of them being a file and another a simple text field.
The call is succesfully forwarded to the backed service but without the actual fields values (the headers instead are correctly passed, though their keys are lower-cased, that is "X-PD20-BillingSubscriptionId" is passed as "x-pd20-billingsubscriptionid").
Any hint on why is this happening?
Thanks
Ok, the problem was the same as described in multipart form data file upload using WSO2 API manger ? and I had to uncomment the declarations for
within the $WSO2_AM/repository/conf/axis2/axis2.xml file (and restart the server).

Cant POST XML over cURL in Unix

I am trying to submit a HTTP POST request into a web server that runs IIS.
curl -X POST -d
but I am getting an HTML page definition in return.
I have looked and didn't find any match, your support will be appreciated.

How do I find the correct url to send curl POST request to?

I am trying to use curl to send a POST request with json.
I use Live HTTP Headers and get the url to send the request to. However it comes back "request denied. you do not have permission to access this page?"
How do I find the correct url?
from Live Http headers, i can see the json data {"var1":"val1","var2":"val2",...}
so i use the following curl command:
curl -H "Accept: application/json" -H "Content-type: application/json" -o output.html -L "http://domain.com/theurl" -d '{"var1":"val1","var2":"val2",...}'
There may be other parts of the request you observed using Live HTTP Headers that allowed your browser to access that URL, such as a cookie value that indicated your session information or user credentials. If Live HTTP Headers has the ability to view those headers and/or cookies, you could grab them and include them in your curl request using additional -H 'Header: value' arguments.
HTTP Authentication may also be used, in which case you should pass your username and password to curl with --user name:password.

Resources