将字符串转换为 http 字符串格式
convert string to http string format
我需要提出 api 请求,我需要转换一个字符串,例如:
"hello i am a special string + i contain special characters?"
转换为如下请求格式:
"hello%20i%20am%20a%20special ... ecc"
python 有图书馆可以帮助我吗?
这是我的代码:
import http.client
conn = http.client.HTTPSConnection("address:port")
conn.request(method="GET", url="/my/target/site?info1=this needs to be converted&info2=also this???", headers=headers)
谢谢
喜欢How to convert a url string to safe characters with python?
并且 How to urlencode a querystring in Python?
您可以使用
import urllib
urllib.parse.quote_plus('string here')
我需要提出 api 请求,我需要转换一个字符串,例如:
"hello i am a special string + i contain special characters?"
转换为如下请求格式:
"hello%20i%20am%20a%20special ... ecc"
python 有图书馆可以帮助我吗?
这是我的代码:
import http.client
conn = http.client.HTTPSConnection("address:port")
conn.request(method="GET", url="/my/target/site?info1=this needs to be converted&info2=also this???", headers=headers)
谢谢
喜欢How to convert a url string to safe characters with python? 并且 How to urlencode a querystring in Python?
您可以使用
import urllib
urllib.parse.quote_plus('string here')