I'm consuming a rest web service in a job in AX 2012.
I use UTF-8, and when I run my job, I get the error: "'CLRObject' could not be created" in line :
dataStream = response.GetResponseStream();
my code is :
postData = strfmt('My json');
new InteropPermission(InteropKind::ClrInterop).assert();
url = "my URL";
request = System.Net.WebRequest::Create(url);
System.Net.ServicePointManager::set_Expect100Continue(false);
request.set_Method("POST");
utf8 = System.Text.Encoding::get_UTF8();
byteArray = utf8.GetBytes(postData);
request.set_ContentType("application/JSON");
request.set_ContentLength(byteArray.get_Length());
dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.get_Length());
dataStream.Close(); try
{
response = request.GetResponse();
}
catch (Exception::CLRError)
{
postdata = "";
}
dataStream = response.GetResponseStream();
streamReader = new System.IO.StreamReader(dataStream);
returnValue = streamReader.ReadToEnd();
please be informed that for the same URL and post data (JSON) I can get correct data in Postman(), but I face the issue in AX.
and I know some thing is wrong with my Unicode, because when I test the same as above code, with another URL and post data for another web service, it results in a response for me, that in it all "&" characters are replaced with Unicode "\u0026" !!!!!
would you please help me?
Guys please be informed that issue solved by adding timeout to request. I thought it may be useful for some one.
request.set_timeout(100000);