Skip to content

Retrieve StreamUri by Postman

This instruction introduce how to retrieve StreamUri by Postman.

Prerequisites

  1. Install Postman

  2. Download and import the following JSON files into Postman REST client tool:

Set Up the Authentication for ONVIF security

Replace the following ONVIF environment variable on the Postman REST client.

  • WS_USERNAME - The username for a certified user
  • WS_NONCE - A random, unique number generated by a client
  • WS_UTC_TIME - The UTC time when the request is made.
  • WS_PASSWORD_DIGEST - a digest that is calculated according to an algorithm defined in the specification for WS-UsernameToken: Digest = B64ENCODE( SHA1( B64DECODE( Nonce ) + Date + Password ) )

How to generate the PasswordDigest?

According to the ONVIF spec and programmer guide, the client needs to provide the password digest for WS-UsernameToken. For example, you can generate the password digest in golang:

package main

import (
    "crypto/sha1"
    "encoding/base64"
    "fmt"
)

func main() {
    nonce := "abcd"
    password := "Password1!"
    created := "2022-06-06T12:26:37.769698Z"
    passwordDigest := generatePasswordDigest(nonce, created, password)

    fmt.Println("Nonce:", nonce)
    fmt.Println("Created:", created)
    fmt.Println("PasswordDigest:", passwordDigest)
}

//Digest = B64ENCODE( SHA1( B64DECODE( Nonce ) + Date + Password ) )
func generatePasswordDigest(Nonce string, Created string, Password string) string {
    sDec, _ := base64.StdEncoding.DecodeString(Nonce)
    hasher := sha1.New()
    hasher.Write([]byte(string(sDec) + Created + Password))
    return base64.StdEncoding.EncodeToString(hasher.Sum(nil))
}
The runnable code: https://go.dev/play/p/ZnE2nZYorg9

Set Up the API Endpoint

Generally, the device web service endpoint is http:/${address}:${port}/onvif/device_service, then you can use GetCapabilities ONVIF function to query other web services' endpoints:

<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope ...>
    <env:Body>
        <tds:GetCapabilitiesResponse>
            <tds:Capabilities>
                <tt:Device>
                    <tt:XAddr>http://192.168.12.123/onvif/device_service</tt:XAddr>
                    ...
                </tt:Device>
                <tt:Events>
                    <tt:XAddr>http://192.168.12.123/onvif/Events</tt:XAddr>
                    ...
                </tt:Events>
                ...
        </tds:GetCapabilitiesResponse>
    </env:Body>
</env:Envelope>

Replace the following ONVIF environment variable on the Postman REST client.

  • DEVICE_ENDPOINT - device web service endpoint
  • MEDIA_ENDPOINT - media web service endpoint
  • EVENT_ENDPOINT - event web service endpoint
  • PTZ_ENDPOINT - ptz web service endpoint

Then you can execute other ONVIF function via Postman REST client tool.

Retrieve the StreamUri

Query the available Profile Token

1.Navigate to the GetProfiles function ( ONVIF -> Video Streaming -> GetProfiles ) and click send button.

query-profiles

The available tokens are 0, 1, 2.

2.Replace the env MEDIA_PROFILE environment variable with the specified profile token.

Check the StreamUri Parameters

Before querying the StreamUri, you can find the available parameters from ONVIF-Media-Service-Spec and media.wsdl.

query-streamuri-parameter-1 query-streamuri-parameter-2

In most cases, cameras support the RTSP when querying GetCapabilities: query-streamuri-parameter-3

Query the StreamUri

Query the StreamUri with the specified parameters: query-streamuri-parameter-4