我正在尝试使用相同的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

但是如果我使用相同的值键在Postman中构建相同的请求:

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

有或没有请求标头信息我只收到服务器的错误响应***我没有使用No Auth授权类型:

{
    "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 Dev工具中的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压缩参数