我正在尝试使用Crossbar的重定向服务重定向http请求(GET)。我对请求使用了'curl‘。重定向似乎工作得很好,但我不能将我的(查询)参数传递到最终目的地。具体地说,我正在做:
curl -L "http://localhost:8008/redirection?num=15"其中,在localhost:8008运行的是纵横制路由器。路径'/redirection‘在Crossbar的配置文件中定义:
"redirection":{
"type": "redirect",
"url": "http://somewhere.com/something"
},来自服务器的响应(例如http://somewhere.com/something)是:
{
"detail": "Missing query parameter 'num'",
"status": 400,
"title": "Bad Request",
"type": "about:blank"
}我做错了什么?
发布于 2017-07-01 22:18:38
我找到了一个解决方案。我不确定这是不是正确的方法,但它是有效的。我在路径为: /usr/local/lib/python3.4/dist-packages/twisted/web.的http.py文件中添加了一些代码行具体来说,我更改了类请求的函数重定向,如下所示:
def redirect(self, url):
"""
Utility function that does a redirect.
The request should have finish() called after this.
"""
########## my code ##########
x = self.uri.split(b'?', 1) #split
if len(x) == 1:
self.path = self.uri #there are no parameters
else:
self.path, argstring = x #argstring = my query parameters
params = '?' + argstring.decode()
url += params.encode() #convert string parameters to bytes and append them to url
################################
self.setResponseCode(FOUND)
self.setHeader(b"location", url)现在,"location“有了新的url +我的查询参数,并且重定向服务(Crossbar)正在将我的参数正确地传递到新的目的地。
如果有更好的解决方案(也许我可以在crossbar中改变一些东西,而不是扭曲的),让我知道!
https://stackoverflow.com/questions/44845546
复制相似问题