Looking to upload any number of map types from a web application and then have ArcGIS online convert them to KML and then send them back the application. If the map can't be converted, give the user an error. Having a hard time getting authenticated. Not looking for the user to have to input credentials, as I have an ArcGIS Online account. After looking at the documentation, it's difficult to understand if the application needs to register, authorize, and then request token before it can contact the online service.
using System;using System.Collections.Generic;using System.Linq;using System.IO;using System.Text;using System.Threading.Tasks;using System.Net.Http;namespace ConsoleApplication1{class Program{ static void Main(string[] args) { ProcessRequest(); } async static void ProcessRequest() { System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("username", "password"); HttpClientHandler handler = new HttpClientHandler { Credentials = credentials }; using (var client = new HttpClient(handler)) { client.BaseAddress = new Uri("http://sampleserver6.arcgisonline.com/"); client.DefaultRequestHeaders.Add("token", "asdasdf"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); Stream stream = File.OpenRead("path.txt"); HttpContent content = new StreamContent(stream); HttpResponseMessage response = await client.PostAsync("arcgis/rest/services/911CallsHotspot/GPServer/uploads/upload#access_token=tokenvalue", content); if (response.IsSuccessStatusCode) { string result = await response.Content.ReadAsStringAsync(); System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); UploadResult upload_result = serializer.Deserialize(result); } } }}class UploadResult{ bool success { get; set; } UploadItem item { get; set; }}class UploadItem{ string itemID { get; set;}}}
أكثر...
using System;using System.Collections.Generic;using System.Linq;using System.IO;using System.Text;using System.Threading.Tasks;using System.Net.Http;namespace ConsoleApplication1{class Program{ static void Main(string[] args) { ProcessRequest(); } async static void ProcessRequest() { System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("username", "password"); HttpClientHandler handler = new HttpClientHandler { Credentials = credentials }; using (var client = new HttpClient(handler)) { client.BaseAddress = new Uri("http://sampleserver6.arcgisonline.com/"); client.DefaultRequestHeaders.Add("token", "asdasdf"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); Stream stream = File.OpenRead("path.txt"); HttpContent content = new StreamContent(stream); HttpResponseMessage response = await client.PostAsync("arcgis/rest/services/911CallsHotspot/GPServer/uploads/upload#access_token=tokenvalue", content); if (response.IsSuccessStatusCode) { string result = await response.Content.ReadAsStringAsync(); System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); UploadResult upload_result = serializer.Deserialize(result); } } }}class UploadResult{ bool success { get; set; } UploadItem item { get; set; }}class UploadItem{ string itemID { get; set;}}}
أكثر...