Here is my F# code that raises the exception of Access denied:
Note: the periods on the left of some lines are to make the spacing show in the post. Indentation is important in F#.
==================================================
I verified that I am using the correct username, token, and domain by using cURL:
THIS WORKS:
cURL --silent --header "Authorization: cpanel indinferaem:IAQY7WHZT9JUJ7U5CJ926N0W4LWO8N0F" "https://assigned-email-manager.com:2083/execute/Email/list_pops"
==================================================
I use the website, assigned-email-manager.com, as a sandbox. Therefore, this post does not contain any secret or private information. At the time of this posting, the token is valid. Later the token will be deleted.
F# uses the same HttpClient that C# uses from .NET. I don't know what cURL does that makes the request work and what HttpClient does that makes the request fail. There must be something wrong with the way I am using HttpClient. But what?
open System
open System.Net.Http
open System.Net.Http.Headers
open System.Text
open System.Diagnostics
[INDENT][/INDENT]
// global constants
let username = "indinferaem"
let token = "IAQY7WHZT9JUJ7U5CJ926N0W4LWO8N0F"
let domain = "assigned-email-manager.com"
let cPanelFunction = "list_pops"
let getEboxList (): unit = // function definition
[INDENT] let authHeader = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{username}:{token}"))[/INDENT]
[INDENT] let client = new HttpClient()[/INDENT]
[INDENT] client.DefaultRequestHeaders.Authorization <- AuthenticationHeaderValue("Basic", authHeader)[/INDENT]
[INDENT] let response = client.GetStringAsync($"https://{domain}:2083/execute/Email/{cPanelFunction}").Result // <<<<< Exception on this line[/INDENT]
[INDENT] Debug.WriteLine(response)[/INDENT]
[INDENT] ()[/INDENT]
Note: the periods on the left of some lines are to make the spacing show in the post. Indentation is important in F#.
==================================================
I verified that I am using the correct username, token, and domain by using cURL:
THIS WORKS:
cURL --silent --header "Authorization: cpanel indinferaem:IAQY7WHZT9JUJ7U5CJ926N0W4LWO8N0F" "https://assigned-email-manager.com:2083/execute/Email/list_pops"
==================================================
I use the website, assigned-email-manager.com, as a sandbox. Therefore, this post does not contain any secret or private information. At the time of this posting, the token is valid. Later the token will be deleted.
F# uses the same HttpClient that C# uses from .NET. I don't know what cURL does that makes the request work and what HttpClient does that makes the request fail. There must be something wrong with the way I am using HttpClient. But what?
Last edited: