ServiceStack JsonServiceClient - Custom HTTP Headers not sent

社会主义新天地 提交于 2019-12-23 09:27:00

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!