'403 Forbidden error while invoking API in c# code

This API is working through postman. I am trying the same thrid-party API from my application like below:

    string requestUrl = string.Empty;
    string result = string.Empty;
    System.Net.WebClient client = new System.Net.WebClient();
    using (client)
    {
        requestUrl = "https://api.fyndx1.de/hogwarts/aggregators/api/v1/config1/authToken";
        client.QueryString.Add("username", "tester");
        client.QueryString.Add("password", "pwd123");
        result = client.DownloadString(requestUrl);
    }

403 error is coming. I tried to add User agent to header parameters after querystring but no use.

    client.Headers.Add("User-Agent: Other");

Any help is appreciated. Thanks.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source