Can I pass custom data in the HTTP header?

前端 未结 7 1168
醉梦人生
醉梦人生 2021-02-12 17:14

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 extr

相关标签:
7条回答
  • 2021-02-12 17:50

    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.

    0 讨论(0)
  • 2021-02-12 17:59

    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.

    0 讨论(0)
  • 2021-02-12 18:05
    Request.Headers.Add("headername", "headervalue");
    Response.Headers.Add("headername", "headervalue");
    
    0 讨论(0)
  • 2021-02-12 18:08

    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).

    0 讨论(0)
  • 2021-02-12 18:08

    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).

    0 讨论(0)
  • 2021-02-12 18:09

    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.

    0 讨论(0)
提交回复
热议问题