FOR TIPS, gUIDES & TUTORIALS

subscribe to our Youtube

GO TO YOUTUBE

14082 questions

16727 answers

27453 comments

53732 members

0 votes
182 views 0 comments
by
Working (GET):

sudo curl -X GET "http://192.168.1.1/cgi-bin/io_state?username=XXX&password=XXX&pin=relay0&state=open"

Respons: OK

Not working (POST):

sudo curl -X POST "http://192.168.1.1/cgi-bin/io_state?username=XXX&password=XXX&pin=relay0&state=open"

Response: Bad username or password

I want to be able to POST the relay to OPEN in 30 sec. The reason for it is that the relay control the power to my computer, and I want to shutdown my computer correctly before the power went out. So I can not have a GET, because then I have to wait.

Regards Terje

Replya minute ago

1 Answer

0 votes
by

Hello,

Both GET and POST are used to transfer data, requests from client to server in HTTP, however, there is a difference in how POST and GET requests are represented. GET requests are appended in URL strings. POST request in itself means sending information in the body. It is not possible to send POST parameters in the URL in a straightforward manner. 

You can read more about POST request creation here: https://linuxize.com/post/curl-post-request/.

You can also use Chrome's add-on Postman for testing purposes: https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop

It should also work if you were to simply enter: curl "http://192.168.1.1/cgi-bin/io_state?username=XXX&password=XXX&pin=relay0&state=open"

Best regards,

Žygimantas