问题
I'm trying to send custom HTTP Headers with a JsonServiceClient but headers are never sent in the query.
I'm using:
JsonServiceClient client = new JsonServiceClient (baseUri);
client.Headers.Add ("X-Parse-Application-Id", "XXXXXX");
client.Headers.Add ("X-Parse-REST-API-Key", "XXXXXX");
Any idea ?
回答1:
You haven't made a request yet. The Headers get added here when you make a request.
An alternative way to add headers is to use the Request filters, e.g:
client.RequestFilter = httpReq => {
httpReq.Headers.Add ("X-Parse-Application-Id", "XXXXXX");
httpReq.Headers.Add ("X-Parse-REST-API-Key", "XXXXXX");
};
Which effectively does the same thing.
回答2:
Here is another way to do it.
_client.RequestFilter = httpReq => httpReq.Headers.Add("X-CUSTOM", "hello");
来源:https://stackoverflow.com/questions/17613773/servicestack-jsonserviceclient-custom-http-headers-not-sent