curl post request failing - linux

I am sending a post request to my site as so :
curl --data "param1=value1&param2=value2" http://mysite.com/
But the result is the entire html page (independently of the username and the password, whether they are right or wrong)

try
`curl -u username:password http://example.com`
to get logged on, or try this
curl http://username:password#example.com/?param1=xx&param2=xx

Related

POST csv/Text file using cURL

How can I send POST request with a csv or a text file to the server running on a localhost using cURL.
I have tried curl -X POST -d #file.csv http://localhost:5000/upload but I get
{
"message": "The browser (or proxy) sent a request that this server could not understand."
}
My server is flask_restful API. Thanks a lot in advance.
There are many alternate ways to accomplish this. One way is
I have used the following:
curl -F ‘data=#<file_location>’ <URL>
Eg. curl -F data=#data.csv localhost:5000/h
Your command can also be changed slightly like this
curl -X POST -H 'Content-Type: text/csv' -d #file.csv http://localhost:5000/upload
The above is one of the many ways.It can be sent either as a part of form or data, or multipart, etc. You can refer Medium Post
Curl's default Content-Type is application/x-www-form-urlencoded so your problem is probably that the data you are POSTing is not actually form data. It might work if you set the content type header properly:
-H "Content-Type: text/csv"
Though it does depend on the server.

How to post raw body data with curl?

Before you post this as a duplicate; I've tried many of the suggestions I found around SO.
So far I've been using postman to post data to a Java web service. That works great as follows:
I now want to do the same using curl, so I tried it using the following ways:
$ curl -X POST --data "this is raw data" http://78.41.xx.xx:7778/
$ curl -X POST --data-binary "this is raw data" http://78.41.xx.xx:7778/
$ curl -X POST --data "#/home/kramer65/afile.txt" http://78.41.xx.xx:7778/
$ curl -X POST --data-binary "#/home/kramer65/afile.txt" http://78.41.xx.xx:7778/
Unfortunately, all of those show an empty raw body on the receiving side.
Does anybody know what I'm doing wrong here? How is my curl request different from my postman request? All tips are welcome!
curl's --data will by default send Content-Type: application/x-www-form-urlencoded in the request header. However, when using Postman's raw body mode, Postman sends Content-Type: text/plain in the request header.
So to achieve the same thing as Postman, specify -H "Content-Type: text/plain" for curl:
curl -X POST -H "Content-Type: text/plain" --data "this is raw data" http://78.41.xx.xx:7778/
Note that if you want to watch the full request sent by Postman, you can enable debugging for packed app. Check this link for all instructions. Then you can inspect the app (right-click in Postman) and view all requests sent from Postman in the network tab :

How to wget/curl past a redirect to download content?

I would like to use wget, curl or even use Perl to download a copy of my projects each night from ShareLatex, but when I look at Network in Chrome, I see it redirects from /login to /projects in a successful login.
Because of the redirect I it flushes the Chrome network debug log, but if I do a wrong login attempt I can see what it sends. See below screenshot.
Question
Can anyone explain how I can figure out which string I should post in order to login?
Is the _csrf header string important?
I have no luck with
curl -s --cookie-jar cookie https://sharelatex.com/login
curl -s --cookie cookie -H 'email: my#email.com' -H 'password: mypw' https://sharelatex.com/login
as it just gives me a failed login screen.
Use -L option in curl:
curl -s -L -H 'email: my#email.com' -H 'password: mypw' https://sharelatex.com/login

linux curl POST request not working

I am trying to make a POST request using curl to retrieve exam results from the page : http://wbutech.net/result_odd.php .... I am using the following syntax but various errors are showing up (like content has moved permanently) although I am using the -L option...
curl -L --data-urlencode "semno=7&rectype=1&rollno=10400111005" http://wbutech.net/show-result.php
can anyone please post the working syntax here which works on the above said link correctly and retrieves the results?
(Sample Usage is enter roll as 10400111005 and click semester7 button under regular students...that is what I am trying to do using the above curl syntax)
Try:
curl -XPOST http://wbutech.net/show-result.php -d '{"semno": 7, "rectype": 1, "rollno": 10400111005}'
Other than 301/302 redirects, this website requires using credentials, try:
curl -u user:passwd -XPOST http://50.28.104.43/show-result.php -d'{"semno": 7, "rectype": 1, "rollno": 10400111005}'
replacing user:passwd with your real username and password.

curl post issues: input password became empty

I'm using "curl" to get a webpage which needs username and password.
For some webpages, I can get the page I want with expression like
curl -u myusername:mypassword url -o output.html.
But for some other webpages, I can't get the page I want.
I've tried expressions mentioned above, it seemes the username and the password is not sent with the request.
I also tried expressions like
curl -d"login_username=myusername&login_password=mypassword&action=login&submit=Login" url -o output.html.
The username is sent, but the password is still empty.
By the way, there is a "realm: LDAP" under username & password inputbox.
Does anybody know what is happening? Thanks in advance.
Assuming that a website uses HTTP basic authentication, a verbose mode, with -v option, makes you confirm whether the authentication request is sent or not. If the authentication request is sent, you can see Authorization header as the below.
$ curl -v -u user:password http://foo.example.com/auth/ -o output.html
* About to connect() to x.x.x.x port 3128
* Trying x.x.x.x... connected
* Connected to proxy.example.com (x.x.x.x) port 3128
* Server auth using Basic with user 'user'
> GET http://foo.example.com/auth/ HTTP/1.1
> Authorization: Basic cm9vdDpSaW5nMjAXMA==
The syntax for cURL username & password is :
user,password
and not
user:password
So finally :
curl -s -v -u myusername,mypassword url

Resources