Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

有简单获取 response.url 的 api 吗 #260

Open
DeemoASCII opened this issue Oct 26, 2020 · 7 comments
Open

有简单获取 response.url 的 api 吗 #260

DeemoASCII opened this issue Oct 26, 2020 · 7 comments

Comments

@DeemoASCII
Copy link

一点小疑惑,文档看了好几遍,似乎没有发现一个比较简单的能获取到Response的URL的方法,类似python的:

import requests
res = requests.get('https://httpbin.org')
print(res.url)
@guonaihong
Copy link
Owner

没怎么玩过python。res.url只是请求的url?从http的请求和响应头设计来看,响应报文里面是没有url信息的,所以res.url只能是请求对象的url参数,或者说res.url只是 requests.get函数的形参拷贝?(我理解的可对)

@guonaihong
Copy link
Owner

对,没有python request的镜像api(res.url)。所以我考虑下是否要加上。我先了解下res.url干了啥。

@DeemoASCII
Copy link
Author

应该是请求的url,但是如果有302跳转的话,返回的是跳转之后的url,所以应该是以最后一次的请求url为准的(我的猜测),主要还是为了发生跳转之后的url,某些场景下面能够直接从url判断是否出现验证码或者请求失败,而不需要去解析页面的内容,比较方便。(在不方便全都一刀切的去禁止跳转的情况下)

@guonaihong
Copy link
Owner

了解了。

@guonaihong
Copy link
Owner

guonaihong commented Oct 27, 2020

确认下,只要包含请求的url和301或者302跳转之后的url就行了?

@DeemoASCII
Copy link
Author

是的,类似这个库 https://github.com/go-resty/resty 中有,response.RawResponse.Request.URL.String()

@guonaihong
Copy link
Owner

ok,了解。后面加下。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants