我可以在HTTP标头中传递自定义数据吗? [英] Can I pass custom data in the HTTP header?

查看:108
本文介绍了我可以在HTTP标头中传递自定义数据吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一大堆Web服务,每个服务都有几个Web方法。这些服务的消费者多种多样。我想用额外的可选参数(Int64或Int32)来扩充这些Web方法中的每一个,但是使用这个额外的(可选参数)添加新方法是很多工作并且让客户端使用新方法将更耗时。

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.

所以我想知道我是否可以允许希望利用此param提供的新功能的客户端可以在HTTP头或其他一些中传递此Int方式。

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.

所以第一个问题是我可以在HTTP标头中传递一个int吗?如果是这样,在C#/ ASP.NET中如何做到这一点?

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?

推荐答案

它有点不正统,我敢肯定一些纯粹主义者会对这个想法感到不满(标题只能用于传递信息,以及不应该包含消息的语义。)

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

实际上它可行,但你想确保所有客户端都可以添加这些标题。如果你的客户正在使用工具来调用web方法而不是自己生成HTTP请求(我希望是这种情况),那么这是一个真正的问题。

Practically its doable, but you want to be sure all your clients can add these headers. If you're clients are using tools to call the webmethods 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?

这篇关于我可以在HTTP标头中传递自定义数据吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆