0

Trying to create test client for NetSuite Restlet web service.

Authorization header should look like:

{"Authorization":"NLAuth nlauth_account=5731597_SB1, nlauth_email=xxx@xx.com, nlauth_signature=Pswd1234567, nlauth_role=3","Content-Type":"application/json"}

Call with parameters should look like:

https://some.ns.restlet.uri&id=111&&amount=22

I do:

            WebRequestHandler handler = new WebRequestHandler();

            HttpClient client = new HttpClient(handler);
            var values = new Dictionary<string, string>
        {
                {"id", "111"},
                {"amount", "22"}
        };
            var content = new FormUrlEncodedContent(values);
            var uri = new Uri(@"https://some.ns.restlet.uri");

            content.Headers.Add(@"Authorization", Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes("NLAuth nlauth_account = 5731597_SB1, nlauth_email = xxx@xx.com, nlauth_signature = Pswd1234567, nlauth_role = 3")));
            content.Headers.Add(@"Content-Type", Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(@"application/json")));



            var response = await client.PostAsync(uri, content);
            var responseString = await response.Content.ReadAsStringAsync();

I got exception while adding first hader:

An exception of type 'System.InvalidOperationException' occurred in System.Net.Http.dll but was not handled in user code
vico
  • 13,725
  • 30
  • 108
  • 237
  • I hope that is not your actual NetSuite account number... ;) – w3bguy Jun 01 '17 at 16:46
  • Not sure if this could cause the issue, but shouldn't your call be `https://some.ns.restlet.uri?id=111&amount=22` – Krypton Jun 01 '17 at 21:26
  • @Krypton No, because it's POST not GET. This is a duplicate of this https://stackoverflow.com/questions/44312426/set-header-when-call-httpclient-postasync/49084966#49084966. There are two answers there. – Sundance.101 Mar 03 '18 at 14:09
  • I'm not sure what your point is - there's nothing stopping a POST having URL parameters. I was simply pointing out that the URL parameters should start with a question mark rather than an ampersand. Also, that question you referenced was asked after this one, so really that one's the duplicate. – Krypton Mar 03 '18 at 15:15
  • @Krypton I see what you mean about the ? beginning to parameters, but a Netsuite restlet url will by default have GET parameters that begin ?script=n&deployment=n, so although he hasn't really written it very clearly, it should work . Ok, so that one is the duplicate, but contains more detail and more answers, rather than just comments, so referenced that as it will be more useful for anyone looking for an answer to this. – Sundance.101 Mar 17 '18 at 09:16

0 Answers0