[英]How to Properly Format geocodeAddresses POST with ArcGIS REST
我能夠使用GET請求成功處理批處理地理編碼請求(此處描述geocodeAddresses-ArcGIS REST API:世界地理編碼服務| ArcGIS for Developers)。 但是,我知道我將要使用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數據(原始)
{
"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"
}
}
]
}
}
我當然已經通過GET請求成功測試了將令牌替換為有效令牌的情況。
我嘗試過的變體包括以“記錄”作為頂級鍵,並包括GET參數(例如令牌)作為POST負載中的鍵。
事實證明,ESRI希望數據以x-www-form-urlencoded的形式發送,而不只是JSON對象。 因此,要正確使用端點,請將其作為formdata發送,其鍵為“ addresses”,值為JSON records對象。
我遇到了同樣的問題,正如您已經指出的那樣:
ESRI希望數據以x-www-form-urlencoded的形式發送,而不只是JSON對象。 因此,要正確使用端點,請將其作為formdata發送,其鍵為“ addresses”,值為JSON records對象。
如果您正在尋找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
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.