Hi;
I created the attached codeunit to communicate with External API via Rest method. How ever I'm getting an error upon run saying "The Remote Server returned an error: (504) Gateway timeout". I'm guessing it is because of the Authentication (combination of Authorization and Key). Here are the Requirements and what I did: (Please note that key I'm providing below is just a sample and not the actual (For security) )
The authorization is too long so I just typed some of it here :
the section of the code in NAV that handle this:
PROCEDURE UploadJson@1000000012(WebServiceURL@1000000000 : Text;String@1000000001 : DotNet "'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.String");
VAR
HttpWebRequest@1000000002 : DotNet "'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.HttpWebRequest";
HttpWebResponse@1000000003 : DotNet "'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.HttpWebResponse";
BEGIN
CreateWebRequest(HttpWebRequest,WebServiceURL,'POST');
SetRequestStream(HttpWebRequest,String);
DoWebRequest(HttpWebRequest,HttpWebResponse,'');
GetResponseStream(HttpWebResponse,String);
END;
PROCEDURE CreateWebRequest@1000000015(VAR HttpWebRequest@1000000002 : DotNet "'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.HttpWebRequest";WebServiceURL@1000000001 : Text;Method@1000000000 : Text);
BEGIN
HttpWebRequest := HttpWebRequest.Create(WebServiceURL);
HttpWebRequest.Timeout := 300000;
HttpWebRequest.Method := Method;
HttpWebRequest.Accept := 'application/json';
HttpWebRequest.ContentType := 'application/json';
HttpWebRequest.Headers.Add('Authorization', dhbAuthText[1]+dhbAuthText[2]+dhbAuthText[3]+dhbAuthText[4]+dhbAuthText[5]+dhbAuthText[6]);
HttpWebRequest.Headers.Add('x-api-key','LViHg8iYYa6VPZqhyemO92swvuo8RiZbage4Y4en');
END;
As I mentioned I did attach the whole codeunit as a text file.
What am I doing wrong or missing here? Please help.. Thank you
CodeUnitObject.txt