我想在(带有pycurl的python)中使用这个cURL命令:
curl -X POST --header "Authorization: key=AAAAWuduLSU:APA91bEStixxx" --header "Content-Type: application/json" https://fcm.googleapis.com/fcm/send -d '{"to" : "fC6xEWZwcu0:APA91xxx", "priority" : "high", "notification" : { "body" : "Background Message", "title" : "BG Title", "sound" : "default"}, "data" : { "title" : "FG Title", "message" : "Foreground Message" }}'
我的源代码是这样的
import pycurl
import re
import io
import json
import requests
data = {"to" : "fC6xEWZwcu0:APA91xxx", "priority" : "high", "notification" : { "body" : "Background Message", "title" : "BG Title", "sound" : "sound.mp3"}, "data" : { "title" : "FG Title", "message" : "Foreground Message" }}
buffer = io.BytesIO()
c = pycurl.Curl()
c.setopt(c.URL, 'https://fcm.googleapis.com/fcm/send')
c.setopt(c.POST, True)
c.setopt(c.SSL_VERIFYPEER, False)
c.setopt(pycurl.HTTPHEADER, [
'Content-type:application/json charset=utf-8',
'Content-Length:0'
'Authorization: Basic key=AAAAWuduLSU:APA91bEStixxx'
])
c.setopt(c.WRITEDATA, buffer)
'''
c.setopt(pycurl.HTTPBODY, [
'test:test'
])
'''
print(buffer)
# c.setopt(c.HEADERFUNCTION, header_function)
c.perform()
print('\n\nStatus: %d' % c.getinfo(c.RESPONSE_CODE))
print('TOTAL_TIME: %f' % c.getinfo(c.TOTAL_TIME))
c.close()
body = buffer.getvalue()
print(body)