2016-07-29 91 views
1

我能夠使用GET請求成功處理批處理地理編碼請求(此處介紹geocodeAddresses-ArcGIS REST API:世界地理編碼服務| ArcGIS for Developers)。但是,我知道我會希望使用POST方法作爲文檔描述,因爲我的批量可能很大。如何使用ArcGIS REST正確地設置geocodeAddresses POST的格式

當我嘗試通過POST提交數據時,我得到一個非常無益的錯誤消息。

{'error': {'code': 400, 
    'details': [], 
    'message': 'Unable to complete operation.'}} 

我試圖讓這個樣子的(我已經試過各種迭代)請求:

網址: http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/geocodeAddresses?sourceCountry=USA&token= & F = pjson

POST數據(RAW)

{ 
    "addresses": { 
     "records": [ 
      { 
       "attributes": { 
        "OBJECTID": 1, 
        "Address": "380 New York St.", 
        "City": "Redlands", 
        "Region": "CA", 
        "Postal": "92373" 
       } 
      }, 
      { 
       "attributes": { 
        "OBJECTID": 2, 
        "Address": "1 World Way", 
        "City": "Los Angeles", 
        "Region": "CA", 
        "Postal": "90045" 
       } 
      } 
     ] 
    } 
} 

當然,TOKEN替換爲有效的令牌,我已經通過GET請求成功地進行了測試。

變化我試過的方法包括將「記錄」作爲頂級密鑰,並在POST有效負載中包含GET參數(如令牌)作爲密鑰。

回答

1

事實證明,ESRI希望數據以x-www-form-urlencoded的形式發送,而不僅僅是一個JSON對象。因此,要正確使用端點,請將其作爲formdata發送,密鑰爲「地址」,值爲JSON記錄對象。

1

我有同樣的問題,因爲你已經指出:

ESRI希望數據能夠作爲X WWW的形式,進行了urlencoded發送,而不是隻是一個JSON對象。因此,要正確使用端點,請將其作爲formdata發送,密鑰爲「地址」,值爲JSON記錄對象。

如果您正在尋找Java實現,您可以考慮使用Form對象(javax.ws.rs.core.Form)。

我已經做到了這種方式:

// Build addresses form object 
Form addressesParam = new Form(); 
addressesParam.param("addresses", buildAddressesParam(addresses).toString()); 

// Try make request and parse it into JSON node 
JsonNode jsonResponse; 
try { 
    String response = webTarget.request(MediaType.APPLICATION_JSON).post(Entity.entity(addressesParam, MediaType.APPLICATION_FORM_URLENCODED_TYPE), String.class); 
    jsonResponse = new ObjectMapper().readTree(response);   
} catch(IOException e) { 
    ... 
} 

當輸入地址被定義爲HashMap<String, String> addresses