tencent cloud

TDMQ for MQTT

Related Agreement
プライバシーポリシー
データプライバシーとセキュリティ契約
ドキュメントTDMQ for MQTT

Publishing MQTT Messages Via HTTP POST

フォーカスモード
フォントサイズ
最終更新日: 2026-04-01 16:37:51

Overview

TDMQ for MQTT allows clients to publish MQTT messages via HTTP(s) POST.
This method supports HTTP 1.0 and 1.1 protocols.
Each successful call to this API is counted as one message toward your TPS, incurring a charge. For details, refer to Billing Details.

Authorization

Similar to WebSocket, the HTTP POST method requires going through the ACL authorization process. When the HTTP 1.0 protocol is used, each message sent triggers the full CONNECT and PUBLISH process, along with corresponding authentication and authorization operations.

Usage Method

Example URL

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

Authentication Method

Two authentication methods are supported: Basic HTTP Authentication and X.509 certificate-based one-device-one-certificate authentication. JWT-based authentication is not yet supported.

Basic HTTP Authentication

The Basic Authentication parameters are described below:
The HTTP request header contains an Authorization field in the following format: Authorization: Basic <credentials>
<credentials> = username:password in Base64 encoding.
username is used for ACL authorization.

BYOC (X.509 Certificate-Based One-Device-One-Certificate Authentication)

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

Request Parameters

Parameter
Semantics
Example Value
Optional
instance-access-point
Access point address of the instance. Go to the TDMQ for MQTT console, choose 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
QoS selected when sending MQTT messages, which defaults to 1, that is, at-least-once.
1
Yes
Retained
Indicates whether the messages sent are retained.
false
No
client_id
Client ID used to send MQTT messages, required for authorization verification.
In the one-device-one-certificate scenario, use the Common Name field of the certificate.
In other scenarios, the default value is http-${connection-id}.
curl001
Yes
username
Username used for connection and message sending, required for authorization verification.
If the Basic Authentication header is used, extract its username part.
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 key of the Nth user property, which must be paired with UserProp.N.Value.
sampleKey
Yes
UserProp.N.Value
Set the value of the Nth user property, which must be paired with UserProp.N.Key.
sampleValue
Yes

Response Description

Response Headers

Header
Semantics
Example Value
X-Message-Id
Message identifier from the MQTT server
A9FE1FEF7EE614DAD5DC8EA6C1A60000

Status Codes

Status Code
Description
200
The request was processed successfully.
400
The server cannot process the request, usually due to missing required fields. Possible causes include:
Incorrect URL path.
Invalid topic name.
Invalid QoS.
Invalid retained value.
401
Authentication and authorization error.
405
The server does not support this HTTP method. Please use the POST method for message sending.
429
Too many messages sent within a short period, exceeding the quota corresponding to the MQTT instance specification.
500
Internal server error.

Example Requests

Example 1

Using 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=false"
Sample Output
* Host mqtt.cloud.tencent.com:80 was resolved.
* Connected to mqtt.cloud.tencent.com (::1) port 80
* using HTTP/1.x
> POST /topics/home?qos=1&client_id=curl-x&retained=false HTTP/1.1
> Host: mqtt.cloud.tencent.com
> User-Agent: curl/8.12.1
> Accept: */*
> Authorization: Basic dXNlcjA6c2VjcmV0MA==
> Content-Length: 29
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 29 bytes
< HTTP/1.1 200 OK
< X-Message-Id: A9FE1FEF7EE614DAD5DC8EA6C1A60000
< content-length: 0
<
* Connection #0 to host mqtt.cloud.tencent.com left intact

Example 2

Using 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

Using 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"



ヘルプとサポート

この記事はお役に立ちましたか?

フィードバック