xnoor,I have forgotten that WebClient is not supporting cookies (but it is required).Override WebClient class to support cookies
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;
}
}
Also you may convert response bytes to string:
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();
}
I have tried this... it works for me...Regards,Vasyl Melnychuk