I have this API call:
HttpResponse<string> response =
Unirest.get("https://wordsapiv1.p.mashape.com/words/" + word.Name)
.header("X-Mashape-Key", "xxxx")
.header("Accept", "application/json")
.asJson<string>();
Here is the class for the HttpResponse
:
public class HttpResponse<T>
{
public HttpResponse(HttpResponseMessage response);
public T Body { get; set; }
public int Code { get; }
public Dictionary<string, string> Headers { get; }
public Stream Raw { get; }
}
I have no problem getting the Body ( response.Body
) or the Code but what I would like to do is to get this header:
[7] = {[X-RateLimit-requests-Remaining, 2498]}
Can someone tell me how I could check the response returned and find out the value of the X-RateLimit-requests-Remaining
?
Dictionaries have something called an indexer . The datatype of your indexer is the datatype of your Key
( Dictionary<Key,Value>
).
Indexers are similar to property getters and setters and are implemented like this:
public TValue this[TKey index]
{
// this will return when being called e.g. 'var x = dictionary[key];'
get { return whatever; }
// and here 'value' is whatever you pass to the setter e.g. 'dictionary[kex] = x;'
set { whatever = value; }
}
In you case that would be:
// "Key" is just an example, use "X-RateLimit-requests-Remaining" instead ;)
response.Headers["Key"];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.