Python执行HTTP命令

发布于 2024-12-21 04:38:34 字数 299 浏览 0 评论 0原文

简而言之,我基本上发现在浏览器地址栏中执行某些字符串会给我带来好处。 例如: http://myip:myport/?CreateOrder=Create+New+Order 在我的数据库中创建一个新订单。

我已经使用 python 设置了我想要传递到该字符串中的变量,但不知道正确的词汇能够准确地计算出如何让 python 执行该字符串,就像它是浏览器一样。

抱歉自己无知。我将不胜感激任何帮助

To be brief, I've basically found that executing certain strings in the address bar in my browser causes good things to happen for me.
For instance: http://myip:myport/?CreateOrder=Create+New+Order creates a new order in my database.

I've used python to set the variables I want passed into that string, but don't know the correct vocab to be able to figure exactly how to get python to execute that string as if it were a browser.

Sorry for being ignorant. I'd appreciate any help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

千年*琉璃梦 2024-12-28 04:38:34

虽然我不确定我是否完全理解您问题的上下文,但您可以使用 在 python 中发出 URL 请求urllib2模块,具体看urlopen函数。

以下是如何提出您所显示的请求的示例:

import urllib2

url_response = urllib2.urlopen('http://myip:myport/?CreateOrder=Create+New+Order')

While I am not sure that I entirely understand the context of your question you can make URL requests in python using the urllib2 module, specifically look at the urlopen function.

Here is an example of how you could make the request you showed:

import urllib2

url_response = urllib2.urlopen('http://myip:myport/?CreateOrder=Create+New+Order')
橙味迷妹 2024-12-28 04:38:34

您应该查看 Requests 模块。

import requests

r = requests.get('http://httpbin.org/get', params={'foo': 'bar'})

print r.content

httpbin.org 是一个很好的调试 HTTP 请求的服务)

结果:

{
  "url": "http://httpbin.org/get?foo=bar",
  "headers": {
    "Content-Length": "",
    "Accept-Encoding": "identity, deflate, compress, gzip",
    "X-Forwarded-Port": "80",
    "Host": "httpbin.org",
    "Accept": "*/*",
    "User-Agent": "python-requests/0.8.3",
    "Connection": "keep-alive",
    "Content-Type": ""
  },
  "args": {
    "foo": "bar"
  },
  "origin": "46.64.26.143"
}

You should check out the Requests module.

import requests

r = requests.get('http://httpbin.org/get', params={'foo': 'bar'})

print r.content

(httpbin.org is a nice service for debugging HTTP requests)

Result:

{
  "url": "http://httpbin.org/get?foo=bar",
  "headers": {
    "Content-Length": "",
    "Accept-Encoding": "identity, deflate, compress, gzip",
    "X-Forwarded-Port": "80",
    "Host": "httpbin.org",
    "Accept": "*/*",
    "User-Agent": "python-requests/0.8.3",
    "Connection": "keep-alive",
    "Content-Type": ""
  },
  "args": {
    "foo": "bar"
  },
  "origin": "46.64.26.143"
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文