When forwarding a message field extracted through a rule to a third-party service, you can customize how to process the data. This is the most flexible way for you to process the message.
Note:The third-party service must be HTTP- or HTTPS-based. To configure forwarding to a third-party service, you need to provide a URL and port number supporting HTTP or HTTPS. After successful forwarding by the rule engine, the third-party service will receive packets from
42.193.134.62
.
The figure below shows the entire process of forwarding data to a third-party service:
For more information on the content and format of the data to be forwarded, please see Data Processing.
Note:To ensure the stable use of your backend, please select Authentication Token.
If Authentication Token is selected for forwarding to the third-party service (i.e., HTTP forwarding), IoT Hub will add the following fields to the header of the HTTP or HTTPS request:
Parameter | Description |
---|---|
Signature | `Signature` combines the `Token` parameter entered in **Add Action** and the `Timestamp` and `Nonce` parameters in the request |
Timestamp | Timestamp |
Nonce | Random number |
Token
, Timestamp
, and Nonce
parameters are sorted in lexicographical order.Signature
and verify whether the request comes from IoT Hub.The sample code used to verify Signature
in PHP is as follows:
private function checkSignature()
{
$signature = $_GET["signature"];
$timestamp = $_GET["timestamp"];
$nonce = $_GET["nonce"];
$token = TOKEN;
$tmpArr = array($token, $timestamp, $nonce);
sort($tmpArr, SORT_STRING);
$tmpStr = implode( $tmpArr );
$tmpStr = sha1( $tmpStr );
if( $tmpStr == $signature ){
return true;
}else{
return false;
}
}
For example, the relevant parameters of a request are as follows, and Token
is set to aaa
.
Nonce: IkOaKMDalrAzUTxC
Signature: c259ed29ec13ba7c649fe0893007401a36e70453
Timestamp: 1604458421
The string after sorting is 1604458421IkOaKMDalrAzUTxCaaa
, and the final SHA1 result is calculated as c259ed29ec13ba7c649fe0893007401a36e70453
.
Service address verification
Parameter | Description |
---|---|
Signature | `Signature` combines the `Token` parameter entered in **Add Action** and the `Timestamp` and `Nonce` parameters in the request |
Timestamp | Timestamp |
Nonce | Random number |
Echostr | Random string |
GET / HTTP/1.1
Host: **.**.**.**:4443
User-Agent: Go-http-client/1.1
Content-Type: application/json
Echostr: UPWIAFASvDUFcTEE
Nonce: testrance
Signature: abb6c316a8134596d825c5a1295bfa6f7657664d
Timestamp: 1623149590
Accept-Encoding: gzip
Echostr
parameter as-is in the body
.HTTP/1.1 200 OK
Date: Tue, 08 Jun 2021 10:53:10 GMT
Content-Length: 16
Content-Type: text/plain; charset=utf-8
UPWIAFASvDUFcTEE
Echostr
parameter to check whether the server URL is valid.The resending mechanism is used to send the message again in case of a failure in the message forwarding process, which makes sure that the message is received. The details are as follows:
Was this page helpful?