tencent cloud

Publishing MQTT Messages Via HTTP POST
最后更新时间:2026-01-30 14:59:41
Publishing MQTT Messages Via HTTP POST
最后更新时间: 2026-01-30 14:59:41

Overview

TDMQ for MQTT supports clients publishing MQTT messages via HTTP(s) POST.
This method supports HTTP 1.0 and 1.1 protocols.
Every successful call to this interface is counted as one message TPS, thereby affecting your billing. For details, refer to Billing Overview.

Usage Method

URL Example

http(s)://${instance-access-point}/topics/${url-encoded-topic-name}?qos=${qos}&retained=${retained}&client_id=${ClientId}&username=${Username}
Fields such as instance-access-point, qos, retained, client_id, username, and so on. For specific definitions, see below Request Parameters.

Authentication Method

Currently supported authentication methods include Basic HTTP Authentication and X.509 certificate-based "unique certificate per device". JWT-based authentication is currently not supported.

Basic HTTP Authentication

The parameters involved in the Basic Authentication process are as follows:
The request's HTTP header field will contain an Authorization field, as follows: Authorization: Basic <credentials>
<credentials> = username:password is the Base64 encoding.
username participates in ACL authorization.

BYOC (Bring Your Own Certificate Based on X.509 Certificate Authentication)

Root certificate trusted by clients: CA.crt
Client certificate chain file: client.chain.crt
Client private key file: client.pkcs8.key

Request Parameter

Parameter
Semantics
Example Value
Optional
instance-access-point
Endpoint address of the instance. Go to the Tencent Distributed Message Queue (MQTT) Console, click Resource > Cluster > Instance ID, and enter the basic information page to obtain it.
mqtt-example-sh-public.mqtt.tencenttdmq.com
No
url-encoded-topic-name
Topic name to be sent, URL encoded.
home
No
QoS
Select QoS when sending MQTT messages, default value is 1, i.e., at-least-once.
1
Yes
Retained
Whether the sent messages are retained messages.
false
No
client_id
Using client-id to send MQTT messages, involved in authorization verification.
If in the one device one certificate scenario, use the Common Name field of the certificate.
In other scenes, the default value is http-${connection-id}.
curl001
Yes
username
Username used for connection and sending, involved in authorization verification.
If using Basic Authentication Header, extract the username part from the Basic Authentication Header.
SampleUser
Yes
ResponseTopic
sample/response/topic
Yes
CorrelationData
SN0001
Yes
ContentType
application/json
Yes
PayloadFormatIndicator
1
Yes
MessageExpiryInterval
3600
Yes
UserProp.N.Key
Set the Nth User Property Key value, must be paired with UserProp.N.Value.
sampleKey
Yes
UserProp.N.Value
Set the Nth User Property Value, must be paired with UserProp.N.Key.
sampleValue
Yes

Request Example

Example 1

Use Basic Authentication (default username).
curl --verbose --request POST -H "Authorization: Basic dXNlcjA6c2VjcmV0MA==" --data "{ \\"message\\": \\"Hello, world\\" }" "http://mqtt.cloud.tencent.com/topics/home?qos=1&client_id=curl-x&retained=true"

Example 2

Use Basic Authentication (specified username).
curl --verbose -k --request POST -H "Authorization: Basic dXNlcjA6c2VjcmV0MA==" --data "{ \\"message\\": \\"Hello, world\\" }" "https://mqtt.cloud.tencent.com/topics/home?qos=1&client_id=curl-x&retained=true&username=sample-user"

Example 3

Use BYOC certificate authentication.
curl --tlsv1.2 \\
--cacert CA.crt \\
--cert client.chain.crt \\
--key client.pkcs8.key \\
--verbose \\
--request POST \\
--data "{ \\"message\\": \\"Hello, world\\" }" \\
"https://mqtt.cloud.tencent.com/topics/home?qos=1"

Authorization

HTTP POST is similar to WebSocket, requiring the ACL authorization process. If using HTTP 1.0 protocol, each transmission will execute the complete CONNECT and PUBLISH processes, along with corresponding authentication and authorization operations.
本页内容是否解决了您的问题?
您也可以 联系销售 提交工单 以寻求帮助。

文档反馈