在研究postmates的API时候https://postmates.com/developer/docs要知道怎么用POST来得到数据
基本URL为https://api.postmates.com/v1/customers/:customer_id/delivery_quotes
API key和customer id从这里可以得到https://postmates.com/developer/testing
所以URL为https://api.postmates.com/v1/customers/cus_KEX15lMKh_770k/delivery_quotes
postmates提到
"Authentication is specified with HTTP Basic Authentication
POST data should be encoded as standard application/x-www-form-urlencoded
The Postmates API requires authentication by HTTP Basic Auth headers. Your API key should be included as the username. The password should be left empty."
Authorization(request header):
Basic access authentication(http://en.wikipedia.org/wiki/Basic_access_authentication)提到client side要a string "username:password"且用Base64加密后在前加上Basic+空格
d067ca26-7eb8-4dab-bebf-30ba3601e0f2:结果是
Authorization: Basic ZDA2N2NhMjYtN2ViOC00ZGFiLWJlYmYtMzBiYTM2MDFlMGYyOg==
Post data:
由上述理论提到post data要用form-urlencoded形式
在request header中加入
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
这个content type也决定了request body用http get的parameter形式name1=value1&name2=value2而不是json形式
request body:
pickup_address=165 Broadway, New York, NY&dropoff_address=2 gold st, New York, NY
在fiddler显示最后的结果为
返回结果:
No comments:
Post a Comment