Can I pass custom data in the HTTP header?

前端 未结 7 1784
北海茫月
北海茫月 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:51

    Its a bit unorthodox and I'm sure some purists would be upset at the idea (the headers should only be used for the transport of the message, and should not contain the semantics of the message).

    Practically its doable, but you want to be sure all your clients can add these headers. If your clients are using tools to call the web methods rather than generating the HTTP requests themselves (which I'd hope is the case) then there's a real chance this is a problem.

    Why is it so hard to add these additional overloads of the methods?

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

    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:02

    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 18:03

    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:09

    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)
提交回复
热议问题