using (System.Net.WebClient client = new System.Net.WebClient()) { client.Headers["Content-type"] = "application/x-www-form-urlencoded"; client.Encoding = System.Text.Encoding.UTF8; var collection = new System.Collections.Specialized.NameValueCollection(); collection.Add("username", adminUserName); collection.Add("password", adminPassword); collection.Add("redirect", http://[server]/ArcGIS/rest/admin/cache/clear); var response = client.UploadValues("http://[server]/ArcGIS/rest/admin/login", "POST", collection); // Process response }
public class CookieAwareWebClient : WebClient { private CookieContainer m_container = new CookieContainer(); protected override WebRequest GetWebRequest(Uri address) { WebRequest request = base.GetWebRequest(address); if (request is HttpWebRequest) (request as HttpWebRequest).CookieContainer = m_container; return request; } }
using (CookieAwareWebClient client = new CookieAwareWebClient()) { client.Headers["Content-type"] = "application/x-www-form-urlencoded"; client.Encoding = System.Text.Encoding.UTF8; var collection = new System.Collections.Specialized.NameValueCollection(); collection.Add("username", adminUserName); collection.Add("password", adminPassword); collection.Add("redirect", "http://[server]/ArcGIS/rest/admin/cache/clear"); var response = client.UploadValues("http://[server]/ArcGIS/rest/admin/login", collection); MemoryStream stream = new MemoryStream(response); StreamReader reader = new StreamReader(stream); String responseString = reader.ReadToEnd(); }
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.