python - 使用端口号和参数构建 HTTP GET 请求

标签 python http get request

我正在尝试做一件非常简单的事情,为包含端口号和一些参数的 get 请求构建一个 URL,如下所示 http://localhost:8080/read?date=whatever

我尝试了几种方法都没有成功,应该不难,但我想不出一个解决方案。

我希望有人能帮助我,我将不胜感激

提前致谢

最佳答案

之前的回答不是针对您实际提出的问题。试试这个:

import urllib

myPort = "8080"
myParameters = { "date" : "whatever", "another_parameters" : "more_whatever" }

myURL = "http://localhost:%s/read?%s" % (myPort, urllib.urlencode(myParameters)) 

基本上,urllib 有一个函数可以做你想做的事,叫做 urlencode。向它传递一个包含您想要的参数/参数值对的字典,它会在“?”之后生成您需要的正确参数字符串。在您的网址中。

关于python - 使用端口号和参数构建 HTTP GET 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4985118/

相关文章:

python - 使用 `get_or_create` 时不隐藏软删除实例

javascript - Angular 6 - 发生错误后 UI 卡住

http - 无法使用 htprouter 读取 Golang 中的帖子表单值

get - Concrete5:我可以在常规页面上使用 $_GET 变量作为查询字符串吗?

python - 如何迭代 Pandas Dataframe 中的行

python - 如何破译这个 cPickle 错误?

iphone - http GET 限制(iPhone)

post - 在浏览器中刷新页面会产生 POST 或 GET 请求?

python - 两个具有一个可选参数差异的 url 映射到 Flask Restful 中的相同资源

REST - 用于检查授权的动词