X++ code to make HTTP request
xml response = "";
System.Net.HttpWebRequest httpRequest = null;
System.Net.HttpWebResponse httpResponse = null;
CLRObject clro = null;
System.IO.Stream stream = null;
System.IO.StreamReader streamReader = null;
System.Byte[] bytes = null;
System.Text.Encoding encoding = null;
try
{
new InteropPermission(InteropKind::ClrInterop).assert();
clro = System.Net.WebRequest::Create(url);
httpRequest = clro;
if(method)
{
httpRequest.set_Method(method);
}
if(header)
{
httpRequest.set_ContentType(header);
}
if(body)
{
encoding = System.Text.Encoding::get_UTF8();
bytes = encoding.GetBytes(body);
httpRequest.set_ContentLength(bytes.get_Length());
stream = httpRequest.GetRequestStream();
stream.Write(bytes,0,bytes.get_Length());
stream.Close ();
}
httpResponse = httpRequest.GetResponse();
stream = httpResponse.GetResponseStream();
streamReader = new System.IO.StreamReader(stream);
response = streamReader.ReadToEnd();
CodeAccessPermission::revertAssert();
}
catch(Exception::CLRError)
{
throw error(AifUtil::getClrErrorMessage());
}
return response;
No comments:
Post a Comment