Sunday, April 14, 2019

RESTLet - URL Encoding for Authentication Password Character - C# (Prevents 401: Error)

When doing Authentication Password, it is good to do URL Encoding for Authentication Password (or nlauth_signature). The reason is, sometime users would have special characters in there password, and NetSuite RESTLet authentication does not accept Special characters unless it is URL Encoded. The following error will then occur: 401 Authorizations Required: INVALID_LOGIN_CREDENTIALS if the correct password has no URL Encoding for Special Characters.

Therefore this article aims to show the function that be can used to do Url Encoding in C#.HttpUtility.UrlEncode(string).

For more information on this function go to: HttpServerUtility.UrlEncode Method (String) - http://msdn.microsoft.com/en-us/library/zttxte6w(v=vs.90).aspx

Sample:

HttpUtility.UrlEncode(password);// password would be a string variable that would have been initialized before. string url = "https://rest.na1.netsuite.com/app/site/hosting/restlet.nl?script=108&deploy=1"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.ContentType = "application/json"; request.Method = "GET"; request.Headers.Add("Authorization:NLAuth nlauth_account=1234567,nlauth_email=email@netsuite.com,nlauth_signature=" + password + ",nlauth_role=3");

No comments:

Post a Comment