- ตัวอย่างการเรียกใช้
- อธิบาย
- https://curl.se/ – Project Page
- GitHub – curl/curl: A command line tool and library for transferring data with URL syntax
- Daniel Stenberg – daniel.haxx.se (founder)
- https://curl.se/docs/manual.html
- https://curl.se/docs/manpage.html
- Swagger Editor
- GitHub – xbklairith/swagger-api-sample: This project contain API Server and API description in swagger format
1.ตัวอย่างการเรียกใช้
> curl -k -s 'https://localhost:44361/api/Products/1'
> curl -i -k -X DELETE 'https://localhost:5001/api/Products/1'
> curl -i -k -H "Content-Type: application/json" -d "{\"name\":\"Plush Squirrel\",\"price\":0.00}" "https://localhost:44361/api/Products"
> curl -i -k -X PUT -H "Content-Type: application/json" -d "{\"id\":2,\"name\":\"Knotted Rope\",\"price\":14.99}" "https://localhost:44361/api/Products/2"
ตัวอย่างการตรวจสอบ client’s public ip ด้วยการเรียกเว็บ ipinfo.io
curl "ipinfo.io/ip"
วางไฟล์ php ไว้ทดสอบเอง
<?php echo 'User IP Address - '.$_SERVER['REMOTE_ADDR']; ?>
2.อธิบาย
-k, --insecure
ยอมให้ใช้งานแบบ insecure
https://curl.haxx.se/docs/manpage.html#-k
(TLS) By default, every SSL connection curl makes is verified to be secure. This option allows curl to proceed and operate even for server connections otherwise considered insecure.
-s, --silent
Silent or quiet mode, คือไม่แสดง error messages
https://curl.haxx.se/docs/manpage.html#-s
Silent or quiet mode. Don’t show progress meter or error messages. Makes Curl mute. It will still output the data you ask for, potentially even to the terminal/stdout unless you redirect it.
-i, --include
ไว้แสดง HTTP response headers
https://curl.haxx.se/docs/manpage.html#-i
Include the HTTP response headers in the output. The HTTP response headers can include things like server name, cookies, date of the document, HTTP version and more…
-H, --header <header/@file>
ส่ง header ไปกับ request
https://curl.haxx.se/docs/manpage.html#-H
(HTTP) Extra header to include in the request when sending HTTP to a server. You may specify any number of extra headers. Note that if you should add a custom header that has the same name as one of the internal ones curl would use, your externally set header will be used instead of the internal one. This allows you to make even trickier stuff than curl would normally do. You should not replace internally set headers without knowing perfectly well what you’re doing. Remove an internal header by giving a replacement without content on the right side of the colon, as in: -H “Host:”. If you send the custom header with no-value then its header must be terminated with a semicolon, such as -H “X-Custom-Header;” to send “X-Custom-Header:”.
-X, --request <command>
ใช้กำหนด HTTP เมธอดที่จะส่ง GET
, POST
, DELETE
and PUT
https://curl.haxx.se/docs/manpage.html#-X
(HTTP) Specifies a custom request method to use when communicating with the HTTP server. The specified request method will be used instead of the method otherwise used (which defaults to GET). Read the HTTP 1.1 specification for details and explanations. Common additional HTTP requests include PUT and DELETE, but related technologies like WebDAV offers PROPFIND, COPY, MOVE and more.
Normally you don’t need this option. All sorts of GET, HEAD, POST and PUT requests are rather invoked by using dedicated command line options.