Content-type
is text/plain
.msgId
will be delivered to the subscriber in the HTTP request header.Parameter Name | Description |
x-cmq-request-id | requestId of the current push message |
x-cmq-message-id | msgId of the current push message |
x-cmq-message-tag | Tag of the current push message |
Parameter Name | Type | Description |
TopicOwner | String | APPID of the owner of the subscribed topic |
topicName | String | Topic name |
subscriptionName | String | Subscription name |
msgId | String | Message ID |
msgBody | String | Message body |
publishTime | Int | Message published time |
http://test.com/cgi
.
JSON format:POST /cgi HTTP/1.1Host: test.comContent-Length: 761Content-Type: text/plainUser-Agent: Qcloud Notification Service Agentx-cmq-request-id: 2394928734x-cmq-message-id: 6942316962x-cmq-message-tag: a, b{"TopicOwner":100015036,"topicName":"MyTopic","subscriptionName":"mysubscription","msgId":"6942316962","msgBody":"test message","publishTime":11203432}
POST /cgi HTTP/1.1Host: test.comContent-Length: 123Content-Type: text/plainUser-Agent: Qcloud Notification Service Agentx-cmq-request-id: 2394928734x-cmq-message-id: 6942316962x-cmq-message-tag: a, btest message
do_POST
method.This sample will print the received HTTP POST request content and deserialize post data json
to traverse the printed request data.#!/usr/bin/pythonfrom BaseHTTPServer import HTTPServer, BaseHTTPRequestHandlerimport jsonclass TestHTTPHandle(BaseHTTPRequestHandler):def do_POST(self):content_len = int(self.headers.getheader('content-length',0))post_body = self.rfile.read(content_len)print "receive cmq topic publisher request:"print self.headersprint post_bodypost_data = json.loads(post_body)for k,v in post_data.iteritems():print "key:%s value:%s" % (k,v)#response http status 200self.send_response(200)self.end_headers()self.wfile.write('ok')def start_server(port):http_server = HTTPServer(('0.0.0.0', int(port)),TestHTTPHandle)http_server.serve_forever()if __name__ == '__main__':start_server(80)
Was this page helpful?