0

I'm trying to access an API, but all the documentation is in PHP and I'm not very familiar with PHP. I am having trouble authenticating to the API. The documentation is here.

Here is what I have so far

var webAddress = "https://xboxapi.com/v2/latest-xbox360-games"; var httpResponse = (new HttpClient().GetAsync(webAddress)).Result; httpResponse.EnsureSuccessStatusCode(); var jsonResponse = httpResponse.Content.ReadAsStringAsync().Result; 

I'm just not sure how to add the authentication header that they are using in PHP.

Any help would be appreciated.

1 Answer 1

3

To add a custom header (in this case X-AUTH), you need to send a custom HttpRequestMessage. For example:

var webAddress = "https://xboxapi.com/v2/latest-xbox360-games"; HttpClient client = new HttpClient(); HttpRequestMessage msg = new HttpRequestMessage(HttpMethod.Get, webAddress); msg.Headers.Add('X-AUTH', 'your-auth-key-here'); HttpResponseMessage response = await client.SendAsync(msg); 
Sign up to request clarification or add additional context in comments.

1 Comment

In addition to the above you can also add the header directly onto the HttpClient if your reusing the HttpClient object HttpClient client = new HttpClient(); client.DefaultRequestHeaders.TryAddWithoutValidation("X-AUTH", "your-auth-key-here");

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.