添加 xml 到 http 重定向
我遇到一种情况,我需要将用户从我的服务器上的页面重定向到另一台服务器上的页面。在此重定向中,我还需要向我重定向到的服务器发送一些 xml。该 xml 文件可能会很长,因此不能只在查询字符串中发送它。
我尝试将 xml 附加到标头中,但标头似乎无法将其发送到另一端。
我知道如何以编程方式创建发送 xml 的请求以及如何重定向,只是不确定如何同时执行这两项操作。
简而言之,我需要 xml 来承载重定向。此重定向将从 MVC 操作中完成。
提前致谢。
编辑
我针对我的问题提出了以下可能的解决方案。不幸的是,它确实利用了我希望避免的两个请求。
基本上,我将 xml 文件作为 post 请求的标头发送,其中还包含会话 id。这是异步发送的。
然后,我重定向用户,在查询字符串中传递相同的 sessionid。这充当将一个请求链接到另一个请求的令牌。我现在只需要等待,看看对方是否愿意使用两个请求来工作。
我还考虑使用一个额外的页面,我可以将用户重定向到该页面,该页面可以包含 Javascript,以便通过一个仅包含一个包含 xml 片段的字段的表单向其他服务器执行额外的表单发布,但这被排除在外我老板的一个可能性(正确,因为这看起来有点像黑客)。
除了两个请求之间存在竞争条件的明显可能性之外,我提出的方法是否还有任何明显或不明显的缺点?
I have a situation whereby I need to redirect a user from a page on my server to a page on another server. In this redirect I need to also send some xml to the server I am redirecting to. This xml file could be quite long so just sending it in the querystring isn't an option.
I have tried attaching the xml in a header but the header doesn't seem to make it to the other end.
I know how to programmatically create requests to send xml and how to redirect, just not sure how to do both at the same time.
In short, I need the xml to piggy-back on the redirect. This redirect will be done from within an MVC Action.
Thanks in advance.
Edit
I have come up with the following potential solution to my problem. Unfortunately it does utilise two requests which I had hoped to avoid.
Basically I send the xml file as a header of a post request which also contains a session id. This is sent asynchronously.
I then redirect the user, passing the same sessionid in the querystring. This acts as a token to link one request to the other. I just need to wait now and find out if the other party are willing to work using two requests.
I also looked in to using an additional page that I could redirect the user to which could contain Javascript to perform an additional form post to the other server with a form that would contain just a single field containing the xml fragment, but this was excluded as a possibility by my boss (rightly so as it seems like a bit of a hack).
Are there any obvious or non-obvious drawbacks to my proposed method, other than the obvious possibility of a race condition between the 2 requests?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以重定向到 http://otherServer/handlerPage.aspx?xmlSource=http%3A%2F%2FfirstServer%2FxmlSource.aspx%3FparameterForXml1%3Dfoo%26parameterForXml2%3Dbar
然后在 http://otherServer/handlerPage.aspx xmlSource 参数是http://firstServer/xmlSource.aspx?parameterForXml1=foo¶meterForXml2=bar可用于获取 XML。
You could redirect to http://otherServer/handlerPage.aspx?xmlSource=http%3A%2F%2FfirstServer%2FxmlSource.aspx%3FparameterForXml1%3Dfoo%26parameterForXml2%3Dbar
Then at http://otherServer/handlerPage.aspx the xmlSource parameter is http://firstServer/xmlSource.aspx?parameterForXml1=foo¶meterForXml2=bar which can be used to obtain the XML.