我正尝试使用相同的API调用realtor.ca来获取待售房屋信息,因此我使用了Chrome开发者工具来查找有关它的详细信息。在Chrome浏览器中,我发现:
General
- Request URL : https://api2.realtor.ca/Listing.svc/PropertySearch_Post
- Method : POST
Request Headers :
POST /Listing.svc/PropertySearch_Post HTTP/1.1
Host: api2.realtor.ca
Connection: keep-alive
Content-Length: 294
Accept: */*
Origin: https://www.realtor.ca
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Referer: https://www.realtor.ca/map
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9,fr;q=0.8
Form Data :
ZoomLevel=15&LatitudeMax=45.6437683&LongitudeMax=-73.7138101&LatitudeMin=45.6317659&LongitudeMin=-73.8093397&CurrentPage=1&PropertyTypeGroupID=1&PropertySearchTypeId=1&TransactionTypeId=2&PriceMin=0&PriceMax=0&BedRange=0-0&BathRange=0-0&RecordsPerPage=12&ApplicationId=1&CultureId=1&Version=7.0
在Chrome开发者工具中,我看到了类似JSON响应:
{"ErrorCode":{"Id":200,"Description":"Success (hidden)","Status":"Pins-Via-Cache:false;Sidebar-Items-Via-Cache:0;","ProductName":"! Push to A2-PR - Realtor API^19791","Version":"1.0.6878.13702"},"Paging":{"RecordsPerPage":12,"CurrentPage":1,"TotalRecords":76,"MaxRecords":600,"TotalPages":7
但是,如果我在邮递员中使用相同的值键建立相同的请求:
https://api2.realtor.ca/Listing.svc/PropertySearch_Post?ZoomLevel=15&LatitudeMax=45.6437683&LongitudeMax=-73.7138101&LatitudeMin=45.6317659&LongitudeMin=-73.8093397&CurrentPage=1&PropertyTypeGroupID=1&PropertySearchTypeId=1&TransactionTypeId=2&PriceMin=0&PriceMax=0&BedRange=0-0&BathRange=0-0&RecordsPerPage=12&ApplicationId=1&CultureId=1&Version=7.0
无论有没有请求标头信息,我都只会从服务器收到错误响应***不是我对授权类型使用了无认证:
{
"ErrorCode": {
"Id": 400,
"Description": "The request was invalid. (hidden)",
"LogId": "",
"ProductName": "! Push to A2-PR - Realtor API^19791",
"Version": "1.0.6878.13702"
},
"Paging": {
"RecordsPerPage": 0,
"CurrentPage": 0,
"TotalRecords": 0,
"MaxRecords": 0,
"TotalPages": 0,
"RecordsShowing": 0,
"Pins": 0
},
"Results": [],
"Pins": []
}
我刚刚发现,如果我使用Chrome开发工具中的cURL请求,请复制该请求:
curl 'https://api2.realtor.ca/Listing.svc/PropertySearch_Post'
-H 'Origin: https://www.realtor.ca'
-H 'Accept-Encoding: gzip, deflate, br'
-H 'Accept-Language: en-US,en;q=0.9,fr;q=0.8'
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36'
-H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8'
-H 'Accept: */*'
-H 'Referer: https://www.realtor.ca/map'
-H 'Connection: keep-alive'
--data 'ZoomLevel=15&LatitudeMax=45.6437683&LongitudeMax=-73.7138101&LatitudeMin=45.6317659&LongitudeMin=-73.8093397&CurrentPage=1&PropertyTypeGroupID=1&PropertySearchTypeId=1&TransactionTypeId=2&PriceMin=0&PriceMax=0&BedRange=0-0&BathRange=0-0&RecordsPerPage=12&ApplicationId=1&CultureId=1&Version=7.0'
--compressed
我看到的cURL和Postman请求之间的唯一区别是cURL压缩参数