python如何分割http请求行?

python如何分割http请求行?,python,python-3.x,python-2.x,Python,Python 3.x,Python 2.x,以下是我的请求行示例: GET https://example.com/hello?ageSelections=0&category=6000&productPeriodType=3&resourcePlace=resourcePlace AND 5089=5089-- PStU&twoCategory=6200 HTTP/1.1 我想拆分此字符串并期待结果: ['GET', 'https://example.com/hello?ageSelections=0&

以下是我的请求行示例:

GET https://example.com/hello?ageSelections=0&category=6000&productPeriodType=3&resourcePlace=resourcePlace AND 5089=5089-- PStU&twoCategory=6200 HTTP/1.1
我想拆分此字符串并期待结果:

['GET', 'https://example.com/hello?ageSelections=0&category=6000&productPeriodType=3&resourcePlace=resourcePlace AND 5089=5089-- PStU&twoCategory=6200', 'HTTP/1.1']

谢谢:-)

您需要更精确地指定它是否是字符串。但考虑到它是一个字符串,它应该如下所示:

string = GET https://example.com/hello?ageSelections=0&category=6000&productPeriodType=3&resourcePlace=resourcePlace AND 5089=5089-- PStU&twoCategory=6200 HTTP/1.1

data = string.split();

当然,如果不是字符串,就不能这样做

使用
str.partition
str.rpartition
的两步方法(也可以通过
str.split
str.rsplit
实现,每次使用
maxslit=1
参数):


这是一个有效的请求吗?请求URI中的空格是什么?如果您有一个有效的请求,请使用@Galen这是我的SQL注入有效负载,不是一个有效的请求:)@caratpine噢goodie!
line = 'GET https://example.com/hello?ageSelections=0&category=6000&productPeriodType=3&resourcePlace=resourcePlace AND 5089=5089-- PStU&twoCategory=6200 HTTP/1.1'
method, _, rest = line.partition(' ')
url, _, protocol = rest.rpartition(' ')
parsed_line = [method, url, protocol]