使用pycurl参数

时间:2016-03-30 20:16:43

标签: python curl parameters pycurl

我第一次尝试使用pycurl而且我不确定如何使用参数。

curl "https://mytest.com/mdb.json" 
-H "Cookie: JSESSIONID=6CCB148AEE7318BD08EFC869E0FD33AB; user=testuser; wmUserPrincipal="%"7B"%"22username"%"22"%"3A"%"22testuser"%"22"%"2C"%"22roles"%"22"%"3A"%"5B"%"5D"%"7D; mf_user=322383eec941db6c72f3f2c7d58b7a80" 
-H "Content-Type: application/json-rpc" 
-H "Accept: */*" 
-H "X-Requested-With: XMLHttpRequest" 
-H "Connection: keep-alive" --data-binary "{""params"":[""1.2.1"",""instance7"",""1.2"",4,{}],""method"":""getMatrix"",""id"":250}" --compressed

正如卷曲中所见:

--data-binary "{""params"":[""1.2.1"",""instance7"",""1.2"",4,{}],""method"":""getMatrix"",""id"":250}" --compressed

我在pycurl中无法弄清楚如何处理它们。也许它甚至不可能,或者可能有一个比使用pycurl更简单的解决方案。

谢谢!

1 个答案:

答案 0 :(得分:0)

让它与requests一起运行,这比我需要的更简单。

cookie = {
    'JSESSIONID': '6CCB148AEE7318BD08EFC869E0FD33AB',
    'user': 'testuser',
    'wmUserPrincipal': '%7B%22username%22%3A%22testuser%22%2C%22roles%22%3A%5B%5D%7D',
    'mf_user': '322383eec941db6c72f3f2c7d58b7a80',
}

head = {
    'Content-Type': 'application/json-rpc',
    'Accept': '*/*',
    'X-Requested-With': 'XMLHttpRequest',
    'Connection': 'keep-alive',
}

data = '{"params":["1.2.1","instance7","1.2",4,{}],"method":"getMatrix","id":250}'

requests.post('https://mytest.com/mdb.json', headers=head, cookies=cookie, data=data)