如何用Python发送原始POST数据?

0 投票
1 回答
3079 浏览
提问于 2025-04-17 00:05

我正在尝试用Python向一个网页发送数据。这个网页上有一个Facebook的游戏,邀请代码是由5个字母组合而成的。我写了一个脚本,把所有可能的字母组合写入了一个txt文件。

这是我需要发送的数据。

http://pastie.org/2409481

这个cookie 'bbbbb' 最后会变成一个变量,然后会循环遍历所有可能的5个字母组合。

[code]invite_code%5D=bbbbb[/code]

1 个回答

0

看看这个链接:Requests,它是一个对urllib2的封装(我记得是这样)。这里有一个页面上的例子:

# This example cooked up by me!

import requests
post_data = {"amount":10000, "service":"writing blog posts"}

r = requests.post('http://example.com/api', post_data, auth=('user', 'pass'))

print r.status_code
print r.headers['content-type']

# ------
# 200
# 'application/json'

你可以为post_data设置你想要的任何内容。

撰写回答