如何方便地将 http request header 转成 curl?

2017-07-28 15:34:01 +08:00
 27
比如这样的一个 post

POST http://bbs.website.com/shop.php HTTP/1.1
Host: bbs.website.com
Accept: application/json, text/javascript, */*; q=0.01
Proxy-Connection: keep-alive
X-Requested-With: XMLHttpRequest
Accept-Encoding: gzip, deflate
Accept-Language: zh-cn
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Origin: http://bbs.website.com
Content-Length: 15
Connection: keep-alive
User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_2 like Mac OS X) AppleWebKit/603.2.4 (KHTML, like Gecko) Mobile/14F89
Referer: http://bbs.website.com/shop.php
Cookie: cid=a8d69UJlhC20nTbgvCVxd%2FeUSYoTnP5YJ0Ps0lzh7g; rand=ed4awTOB1U; acw_tc=AQAAAGrGOS/Ibg4AY7c5cZRocGCvrhpM;

这个 header 是从手机上的 anyflow 嗅探来的一个 request,现在有没有什么方法能直接转成方便直接发送的格式(比如 curl,或者 python 的 requests 也行)?
2664 次点击
所在节点    问与答
4 条回复
15015613
2017-07-28 15:47:43 +08:00
可以用 python 写个脚本,先正则提取请求参数,然后直接调用 requests 库。
kfll
2017-07-28 15:54:33 +08:00
用 netcat 发
veelog
2017-07-28 16:01:55 +08:00
包重放?
ysc3839
2017-07-28 22:11:24 +08:00
随手写了个
```
with open('http.txt') as f:
lines = f.readlines()
method, url, version = lines[0].split(' ')
curl = "curl '%s'" % url
if method != 'GET': curl += ' -X %s' % method
del lines[0]
for line in lines:
curl += " -H '%s'" % line
print(curl)
```

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/378640

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX