我不太确定是在这里还是在 GIS Stack Exchance 中问这个问题。可能两者兼而有之。但我觉得我在这里做了一些根本错误的事情 - 更新似乎没有生效(当我之后查看控制台时它仍然是错误的)。
我正在用 C# 编写一个流程来更新要素图层的定义并使其能够同步。到目前为止,我为其他进程(上传新文件和下载查询)编写的代码位工作正常,我只是遇到了一些问题,并认为我需要一些指针。官方资源可以在以下链接中找到:
我的代码是:
static async Task<string> ReSync(string myToken, string ServiceUrl)
{
try
{
var client = new System.Net.Http.HttpClient();
HttpContent content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("f", "json"),
new KeyValuePair<string, string>("token", myToken),
new KeyValuePair<string, string>("async", "true"),
new KeyValuePair<string, string>("syncEnabled", "true"),
new KeyValuePair<string, string>("capabilities", "Query,Editing,Create,Update,Delete,Sync")
});
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
var response = await client.PostAsync(ServiceUrl, content);
var responseString = await response.Content.ReadAsStringAsync();
return responseString + " <> " + ServiceUrl + " <> " + content;
}
catch (Exception exception)
{
return exception.ToString();
}
}
我的 ServiceUrl 是这样的:
返回的 responseString(响应、ServiceUrl 和内容,按此顺序)是:
{“statusURL”:“ https://servicesX.arcgis.com//MyCompanyID/ArcGIS/rest/admin/services/MyLayerName/FeatureServer/updateDefinition/a-few-numbers-go-here ”} <> https:// servicesX.arcgis.com/MyCompanyID/arcgis/rest/admin/services/MyLayerName/FeatureServer/updateDefinition <> System.Net.Http.FormUrlEncodedContent
如果我手动(从 ArcGIS Online 控制台)执行此操作并在 Chrome 的 DevTools 中记录响应,我们会得到(重要位):
一般的
请求方法:POST
表格数据
updateDefinition: {"hasStaticData":false,"capabilities":"查询、编辑、创建、更新、删除、同步","editorTrackingInfo":{"enableEditorTracking":false,"enableOwnershipAccessControl":false,"allowOthersToUpdate":true, "allowOthersToDelete":true,"allowOthersToQuery":true,"allowAnonymousToUpdate":true,"allowAnonymousToDelete":true}}
异步:真
f: json
代币:LotsAndLotsOfCharactersAndStuff