Can I pass custom data in the HTTP header?

2020-07-01 07:03发布

I have a whole bunch of web services each with several web methods. The consumers of these services are varied and many. I want to augment each of these web methods with an extra optional parameter (Int64 or Int32) but adding new methods with this extra (optional parameter) is a lot of work and getting the clients to use the new methods will be even more time consuming.

So I was wondering if I could allow the clients that wanted to take advantage of the new feature that this param provides could pass this Int in the HTTP header or some other way.

So the first question is can I pass an int in the HTTP header? If so, how would one do that in C#/ASP.NET?

Otherwise, what other suggestions do you have for tackling this problem?

7条回答
2楼-- · 2020-07-01 07:15

I've used this concept once to handle logout redirect for ajax calls in an intranet web application (nothing related to webservice).

it was my best solution at hand, but as some other have said it depends if you can push the constraint to clients to treat theses headers for your purpose.

Definitely not a thing you would want to do by default.

查看更多
Fickle 薄情
3楼-- · 2020-07-01 07:18
Request.Headers.Add("headername", "headervalue");
Response.Headers.Add("headername", "headervalue");
查看更多
祖国的老花朵
4楼-- · 2020-07-01 07:23

Yes it is allowed - but note that it may cut off the ability to use proxies and sometimes http aware firewalls (they tend to inspect and rewrite headers).

查看更多
别忘想泡老子
5楼-- · 2020-07-01 07:25

Note that while it's fine to consume custom headers in ASP.NET it's not always possible to produce custom headers in ASP.NET. You can only do this if you're running ASP.NET integrated mode (i.e. IIS 7.0).

查看更多
可以哭但决不认输i
6楼-- · 2020-07-01 07:26

You can, but you have to define a Header, then set its value. Like in the HttpWebRequest you can add any header, as long as its not one of the reserved ones.

查看更多
虎瘦雄心在
7楼-- · 2020-07-01 07:31

You can, but this defeats the whole purpose of using webservices in the first place. Similar to the saying that each formula in a popular science books reduces the audience to a half, each quick hack increasing the complexity of the interface will mean a lot of trouble in the future.

查看更多
登录 后发表回答