locked
Javascript NetworkCredential How To RRS feed

  • Question

  • Hi to all,

    I need to "Translate" my code from C# to JavaScript about login with NetworkCredential.

    My C# code:

    var httpClientHandler = new HttpClientHandler() { Credentials = new NetworkCredential("user", "password", "domain"), }; using (HttpClient client = new HttpClient(httpClientHandler)) { try { client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var content = new StringContent("[\r\n {\r\n \"userId\": \"21221121\",\r\n \"personnelNumber\": \"22222222\",\r\n \"fullName\": \"1111\",\r\n \"firstName\": \"3333\",\r\n \"secondName\": \"string\",\r\n \"validFrom\": \"2017-10-06T14:11:51.483Z\",\r\n \"organizationUnit\": \"test\",\r\n \"paraset\": \"GR00\"\r\n }\r\n]", Encoding.UTF8, "application/json"); var res = await client.PostAsync("https://sis-test.bizerba.com/interface/api/v1/users/GR", content); } catch (Exception ex) { string e = ex.message; }

    }

    How can this be in JavaScript?

    Thanks in advance

    Friday, October 6, 2017 4:58 PM