13 Ağustos 2010 Cuma

AX2009 How to get XML from site using proxy

xml TNC_getXML()
{
System.Net.HttpWebResponse httpresponse;
System.Net.WebRequest webrequest;
System.Net.WebResponse webResponse;
System.Net.HttpWebRequest httprequest;
System.Net.IWebProxy proxy;
System.Net.WebPermission webPermission;

System.IO.Stream stream;
System.IO.StreamReader streamreader;
System.Text.Encoding encoding;
xml xml;
interopPermission interopPermission;
int i;

interopPermission = new InteropPermission(InteropKind::ClrInterop);
InteropPermission.assert();
try
{

webrequest = System.Net.WebRequest::Create("../../...xml");

proxy = System.Net.WebRequest::GetSystemWebProxy();
proxy.set_Credentials(System.Net.CredentialCache::get_DefaultCredentials());
webRequest.set_Proxy(proxy);

httpresponse = webRequest.GetResponse();
stream = httpresponse.GetResponseStream();
streamreader = new System.IO.StreamReader(stream);

xml = streamreader.ReadToEnd();

codeAccessPermission::revertAssert();
}
catch
{
error("Connection Error");
}
}

Hiç yorum yok: