1

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.

Bin
  • 59
  • 5
  • You may have missed to pass the API access key or token via another Http Header - check again. – Anand Sowmithiran Apr 30 '22 at 09:46
  • This is the api call to get the token. – Bin Apr 30 '22 at 09:48
  • Then apart from the username and password in Query string, that API is expecting some other Header or a query string value that you are not sending, hence it is returning you the 403. – Anand Sowmithiran Apr 30 '22 at 09:49
  • Then how is it working in postman. Am i missing something? – Bin Apr 30 '22 at 10:23
  • Is that webserver using TLS 1.2 or SSL3, how is postman configured? check that. Based on that, this SO [answer](https://stackoverflow.com/a/20097642/14973743) may be tried, to use Ssl3 if your server not handling TLS 1.2 or vice versa. – Anand Sowmithiran Apr 30 '22 at 10:31
  • For .NET 4.5 or later, use `ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;` – Anand Sowmithiran Apr 30 '22 at 10:44
  • After adding this line also, same 403 error. I have added all the request headers from postman also but no progress. – Bin Apr 30 '22 at 17:04
  • There is nothing else I can suggest, just ensure any `SSL certificate config` done in `postman` are also available to your code too, and all the required HTTP `headers` and query `params` are being sent. Other than this, no reason for 403 error. BTW, why are u not using `HttpClient` instead? – Anand Sowmithiran Apr 30 '22 at 17:28

0 Answers0