Как использовать cURL для отправки POST-запросов

How to Use cURL to Send POST Requests

???? ?? ???????????, ?????????? ? API, ?????? ?????????? POST-??????? ? ??????? cURL ???????????. ??? ???? ?? ????? ??????? ???????? ??????????? ?????????, ????????? ?????? ??? ????????????????? ? ????????? ????? ?? ?????????.

? ???? ????? ?? ???????, ??? ?????????? POST-??????? ? ??????? cURL, ??? ?????????? JSON, XML, ????? ? ?????? ????.

??? 1: ?????????? ?? cURL?

? ??????????? ?????? cURL ??? ??????????. ????? ????????? ???, ???????? ???????? ? ????????? ??????? ????:

curl --version

If it’s not installed, download it from curl.se. Windows users may need Git Bash or WSL to get the best results.

??? 2: ??????? POST-??????

??? ??????? ?????? POST-??????? ? ?????????????? cURL:

curl -X POST -d "Hello" https://example.com/api
  • -X POST = HTTP-?????
  • -d = ??????, ??????? ?? ??????????? ? ???? ???????

??? 3: ???????? ????????? Content-Type

????? ???????? ???????, ????? ?????? ?? ???????????, ??????????? ???????? ????????? Content-Type:

??? ???????? ??????:

curl -X POST -H "Content-Type: text/plain" -d "Hello" https://example.com/api

??? JSON:

curl -X POST -H "Content-Type: application/json" \
-d '{"name":"Alice","age":30}' https://example.com/api

??????????? ????????? ??????? ??? JSON, ????? ???????? ?? ??????? ??-?? ?????????? ??????? ???????.

??? 4: ???????? XML-??????

???? API ??????? XML:

curl -X POST -H "Content-Type: application/xml" \
-d '<?xml version="1.0"?><user><name>Alice</name></user>' \
https://example.com/api

??? 5: ???????? ?????? ? -F

????? ????????? ????? (????????, ???????????, ????????? ??? ????):

curl -X POST -F "file=@/path/to/file.jpg" https://example.com/upload

???????? ?????????? ??????:

curl -X POST \
-F "image1=@/path/to/one.jpg" \
-F "image2=@/path/to/two.jpg" \
https://example.com/upload

cURL ????????????? ???????????? multipart/form-data.

??? 6: ???????? ?????? ?????

??? ???????????? ???????? ???? (????????, ????? ? ??????? ??? ???????? ????? ???????? ?????):

curl -X POST -d "username=test&password=1234" https://example.com/login

?? ????? ?????? ?????????? ????????? ????? ????? ? ?????????????? ??????? -d ??? ?????????? ?? ? ???? ??????.

??? 7: ???????? ??????? ??????????????

???? ???????? ??????? ??????? ??????, ??????????? -u:

curl -u username:password https://example.com/secure

??? ????????????? ????????? ????????? Authorisation ? ???????????? Base64.

????????????? cURL ? ????????????? ??????

???? ?? ?????????? ???-??????????????? ????????? ??? ?????? ?????? ???????????, ??????????? cURL ? ?????? ??? ???:

curl -x http://proxyuser:[email protected]:5959 \
-X POST -d '{"action":"test"}' https://example.com/api

At Thunderproxy.com, we provide residential proxies that work perfect with cURL. This is helpful when testing websites from different locations or when you need to bypass rate limits.

????

cURL is a tool for developers, system administrators and testers. It’s fast and efficient — whether you are sending JSON, uploading files, or logging into protected endpoints.

Once you learn the basic flags (-X-d-H-F-u), you’ll be comfortable to create any kind of HTTP request in seconds.


Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *