Tarayıcıdan bir adrese GET ve POST istekleri göndermek yerine, aynı işlemi komut satırından cURL ile yapabiliriz. Bu işlemin nasıl yapıldığını görmek için aşağıdaki örneği inceleyin.


Tarayıcıdan normal GET isteği


Eğer tarayıcıdan http://football.local/app_dev.php/backend/user?page=1&limit=2 adresine giderseniz, cevap aşağıdaki gibi olur.


Cache-Control → no-cache
Connection → Keep-Alive
Content-Length → 217
Content-Type → application/json
Date → Sat, 27 Jun 2015 18:34:58 GMT
Keep-Alive → timeout=5, max=100
Server → Apache/2.4.10 (Unix) PHP/5.6.9
X-Debug-Token → 946971
X-Debug-Token-Link → /app_dev.php/_profiler/946971
X-Powered-By → PHP/5.6.9

{
"users": [
{
"id": 1,
"username": "inanzzz",
"password": "09cd68a2a77b22a312dded612dd0d9988685189f"
},
{
"id": 2,
"username": "robertdeniro",
"password": "09cd68a2a77b22a312dded612dd0d9988685189f"
}
],
"page": "1",
"limit": "2",
"total": 6
}

Aynı işlemin cURL versiyonu


Versiyon 1


Inanzzz-MBP:football inanzzz$ curl -v -X GET http://football.local/app_dev.php/backend/user?page=1&limit=2
[3] 26544
[2] Done curl -v -X GET 127.0.0.1/app_dev.php/backend/user?page=1
Inanzzz-MBP:football inanzzz$ * Hostname was NOT found in DNS cache
* Trying 127.0.0.1...
* Connected to football.local (127.0.0.1) port 80 (#0)
> GET /app_dev.php/backend/user?page=1 HTTP/1.1
> User-Agent: curl/7.37.1
> Host: football.local
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Sat, 27 Jun 2015 18:49:57 GMT
* Server Apache/2.4.10 (Unix) PHP/5.6.9 is not blacklisted
< Server: Apache/2.4.10 (Unix) PHP/5.6.9
< X-Powered-By: PHP/5.6.9
< Cache-Control: no-cache
< X-Debug-Token: 99d00d
< X-Debug-Token-Link: /app_dev.php/_profiler/99d00d
< Content-Length: 215
< Content-Type: application/json
<
* Connection #0 to host football.local left intact
{"users":[{"id":1,"username":"inanzzz","password":"09cd68a2a77b22a312dded612dd0d9988685189f"},{"id":2,"username":"robertdeniro","password":"09cd68a2a77b22a312dded612dd0d9988685189f"}],"page":"1","limit":2,"total":6}

Versiyon 2


Inanzzz-MBP:football inanzzz$ curl -v -X GET -H "application/json" -d '{"page":"1","limit":"2"}' http://football.local/app_dev.php/backend/user
* Hostname was NOT found in DNS cache
* Trying 127.0.0.1...
* Connected to football.local (127.0.0.1) port 80 (#0)
> GET /app_dev.php/backend/user HTTP/1.1
> User-Agent: curl/7.37.1
> Host: football.local
> Accept: */*
> Content-Length: 24
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 24 out of 24 bytes
< HTTP/1.1 200 OK
< Date: Sat, 27 Jun 2015 18:52:34 GMT
* Server Apache/2.4.10 (Unix) PHP/5.6.9 is not blacklisted
< Server: Apache/2.4.10 (Unix) PHP/5.6.9
< X-Powered-By: PHP/5.6.9
< Cache-Control: no-cache
< X-Debug-Token: fd3a65
< X-Debug-Token-Link: /app_dev.php/_profiler/fd3a65
< Content-Length: 213
< Content-Type: application/json
<
* Connection #0 to host football.local left intact
{"users":[{"id":1,"username":"inanzzz","password":"09cd68a2a77b22a312dded612dd0d9988685189f"},{"id":2,"username":"robertdeniro","password":"09cd68a2a77b22a312dded612dd0d9988685189f"}],"page":1,"limit":2,"total":6}

Tarayıcıdan normal POST isteği


Eğer POST ile {"username": "inanzzz", "password": "mypassword"} verisini http://football.local/app_dev.php/backend/user adresine gönderirseniz, cevap aşağıdaki gibi olur.


Cache-Control → no-cache
Connection → Keep-Alive
Content-Length → 13
Content-Type → application/json
Date → Sat, 27 Jun 2015 19:00:49 GMT
Keep-Alive → timeout=5, max=100
Server → Apache/2.4.10 (Unix) PHP/5.6.9
X-Debug-Token → 514fe0
X-Debug-Token-Link → /app_dev.php/_profiler/514fe0
X-Powered-By → PHP/5.6.9

"USER create"

Aynı işlemin cURL versiyonu


Inanzzz-MBP:football inanzzz$ curl -v -X POST -H "application/json" -d '{"username": "inanzzz", "password": "mypassword"}' http://football.local/app_dev.php/backend/user 
* Hostname was NOT found in DNS cache
* Trying 127.0.0.1...
* Connected to football.local (127.0.0.1) port 80 (#0)
> POST /app_dev.php/backend/user HTTP/1.1
> User-Agent: curl/7.37.1
> Host: football.local
> Accept: */*
> Content-Length: 47
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 47 out of 47 bytes
< HTTP/1.1 200 OK
< Date: Sat, 27 Jun 2015 19:02:41 GMT
* Server Apache/2.4.10 (Unix) PHP/5.6.9 is not blacklisted
< Server: Apache/2.4.10 (Unix) PHP/5.6.9
< X-Powered-By: PHP/5.6.9
< Cache-Control: no-cache
< X-Debug-Token: 0d3815
< X-Debug-Token-Link: /app_dev.php/_profiler/0d3815
< Content-Length: 13
< Content-Type: application/json
<
* Connection #0 to host football.local left intact
"USER create"