Example:
I can paste this into the browser URL bar and it pauses/plays VLC
http://:[email protected]:8080/requests/status.xml?command=pl_pause
I cannot get AHK to submit the same URL successfully. It fails on the password:
Code: Select all
#Numpad8::
{
cmd=127.0.0.1:8080/requests/status.xml?command=pl_pause
info:=UrlDownloadToVar(cmd)
MsgBox % "Response " . info
}
urlDownloadToVar(url,raw:=0,userAgent:="",headers:="",Username:="",Password:="vlcremote"){
if (!regExMatch(url,"i)http?://"))
url:="http://" url
try {
hObject:=comObjCreate("WinHttp.WinHttpRequest.5.1")
hObject.open("GET",url)
hObject.SetCredentials(Username,Password,0)
if (userAgent)
hObject.setRequestHeader("User-Agent",userAgent)
if (isObject(headers)) {
for i,a in headers {
hObject.setRequestHeader(i,a)
}
}
hObject.send()
return raw?hObject.responseBody:hObject.responseText
} catch e
return % e.message
}
I tried passing the URL as http://:[email protected]:8080/requests/status.xml?command=pl_pause directly and I tried using .SetCredentials() but it is the same issue.<?xml version="1.0" encoding="ascii" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml10/DTD/xhtml10strict.dtd">
<html lang="en">
<head>
<title>Unauthorized</title>
</head>
<body>
<h1>401 Unauthorized (/requests/status.xml)</h1>
<hr />
<a href="http://www.videolan.org">VideoLAN</a>
</body>
</html>