Got it. Based on the screenshot you sent me, this is in fact a GET request (somewhat odd, not the weirdest thing in the world).
The real problem doing this from Ignition scripting is going to be replicating the --digest
flag. There's no built in support in the native HTTP client for digest authentication, so you'll have to script it yourself.
This LLM guided output might get you there?
# Imports for hashing, URL encoding, and random number generation
from java.security import MessageDigest, SecureRandom
from java.math import BigInteger
from urllib import urlencode
import re
# --- Helper Functions ---
def md5(text):
"""Calculates the MD5 hash of a string and returns a lowercase hex digest."""
md = MessageDigest.getInstance("MD5")
md.update(text.encode('utf-8'))
digest = md.digest()
return BigInteger(1, digest).toString(16).zfill(32)
def parse_auth_header(header_value):
"""Parses a WWW-Authenticate header string into a dictionary."""
if header_value.lower().startswith('digest '):
header_value = header_value[7:]
# Regex to find all key="value" or key=value pairs
parts = re.findall(r'(\w+)="([^"]*)"|(\w+)=([^\s,]+)', header_value)
auth_dict = {}
for key1, val1, key2, val2 in parts:
if key1: # Quoted value match
auth_dict[key1] = val1
else: # Unquoted value match
auth_dict[key2] = val2
return auth_dict
# --- Main Script ---
# 1. Define Request Details
base_url = "http://111.111.111.111/cgi-bin/configManager.cgi"
uri_path = "/cgi-bin/configManager.cgi" # The path portion of the URL
username = "admin"
password = "*passw*" # <-- IMPORTANT: Replace with your actual password
queryParams = {
"action": "setConfig",
"ChannelTitle[0].Name": "1234|5678"
}
# 2. Perform Initial Request to Get the Server Challenge
client = system.net.httpClient()
initial_response = client.get(url=base_url, params=queryParams)
# 3. Extract Challenge Details from the Header
auth_header = initial_response.getHeaders().get("WWW-Authenticate")
challenge = parse_auth_header(auth_header)
realm = challenge['realm']
qop = challenge['qop']
nonce = challenge['nonce']
opaque = challenge.get('opaque', '') # Use .get() as opaque is optional
# 4. Generate Client Values and Calculate Hashes
nc = '00000001' # Nonce count, starts at 1
cnonce = BigInteger(130, SecureRandom()).toString(16)[:16] # Random client nonce
full_uri = uri_path + "?" + urlencode(queryParams)
# Calculate the three required hashes
HA1 = md5(username + ":" + realm + ":" + password)
HA2 = md5("GET:" + full_uri)
response_hash = md5(HA1 + ":" + nonce + ":" + nc + ":" + cnonce + ":" + qop + ":" + HA2)
# 5. Construct the Final Authorization Header
auth_string = (
'Digest username="{username}", realm="{realm}", nonce="{nonce}", uri="{uri}", '
'qop={qop}, nc={nc}, cnonce="{cnonce}", response="{response}", opaque="{opaque}"'
).format(
username=username, realm=realm, nonce=nonce, uri=full_uri, qop=qop,
nc=nc, cnonce=cnonce, response=response_hash, opaque=opaque
)
# 6. Make the Final, Authenticated Request
# This request will throw an error if it fails, as requested.
final_response = client.get(
url=base_url,
params=queryParams,
headers={'Authorization': auth_string}
)
# If the script reaches this point, the request was successful.
# You can now work with the response, for example:
print "Request successful. Response Body:"
print final_response.text