Performing a GET with a POST using a Data API

Sometimes you can only do a GET when you need to do a DELETE, since some systems don't support all of the HTTP verbs. Also since Flash doesn't let you set a custom Authorization header on a GET, sometimes you need to do a GET with a POST. How can you do this? With the X-HTTP-Method-Override header:
X-HTTP-Method-Override: GET
For example, say you want to perform a video search in YouTube using a POST request:
POST /feeds/api/videos HTTP/1.1
Host: gdata.youtube.com
X-HTTP-Method-Override: GET
Content-Length: 23
Content-Type: application/x-www-form-urlencoded

vq=kitten&max-results=1
This is the same as performing a GET on http://gdata.youtube.com/feeds/api/videos?vq=kitten&max-results=1 The POST body is used as the set of query parameters. You can also do this using the curl command:
curl -H "X-HTTP-Method-Override: GET" -X POST http://gdata.youtube.com/feeds/api/videos -d "vq=kitten&max-results=1"

4 comments:

  1. Bài viết rất hay và có ích cho mình, thank bạn rất nhiều
    Lý Thanh Trúc
    Chuyên viên tư vấn:
    Click nếu bạn quan tâm: chữa bệnh men gan tăng cao hiệu quả, chua benh men gan tang cao nhanh nhất

    ReplyDelete
  2. Casino889 nơi nhận định bóng đá hôm nay uy tín hàng đầu tại Việt Nam cùng nhiều chương trình khuyến mại hấp dẫn, nhận ngay hoa hòng cao gấp 6 lần

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete