2019-08-05, 01:14 AM
I have a ton of utilities and a client that I am dragging up to v5 compatibility. All of them currently read and/or modify the database directly and I am trying to get away from that using the http calls.
I know you are super busy and I'm trying to bug you as little as possible. Right now I am trying to learn by reproducing the calls that the web client makes.
My question is this: Do I need to login to use calls like: "/services/service?method=channel.list&format=json"? or is logging in irrelevant for applications?
When the web page logs in, it gets a return code of 302.
When I login using the code below, I get a return code of 200. Yet, I can get a channel listing.
So, I am confused at this point. Did I login successfully? Do I need to login at all? Did I get the channel listing because I am already logged in with the web interface in chrome? How do I log out?
Thanks for your help!
JLM
I know you are super busy and I'm trying to bug you as little as possible. Right now I am trying to learn by reproducing the calls that the web client makes.
My question is this: Do I need to login to use calls like: "/services/service?method=channel.list&format=json"? or is logging in irrelevant for applications?
When the web page logs in, it gets a return code of 302.
When I login using the code below, I get a return code of 200. Yet, I can get a channel listing.
So, I am confused at this point. Did I login successfully? Do I need to login at all? Did I get the channel listing because I am already logged in with the web interface in chrome? How do I log out?
Code:
//function doLogin()
//{
// var salt = getParameterByName("salt");
// var username = $("#email").val();
// var password = MD5($("#password").val());
// var combined = MD5(salt + ":" + username + ":" + password);
// window.location.href = 'login.html?hash=' + combined;
//}
public async Task<bool> doLogin()
{
string url = "http://192.168.86.25:8866";
try
{
//login
fHttpResponseMsg = await fHttpClient.GetAsync(url);
fHttpRequestMsg = fHttpResponseMsg.RequestMessage;
string query = fHttpRequestMsg.RequestUri.Query;
var parts = HttpUtility.ParseQueryString(query);
string salt = parts.Get("salt");
string passMD5 = CreateMD5("password").ToLower();
string hash = CreateMD5(string.Format("{0}:{1}:{2}", salt, "admin", passMD5));
hash = hash.ToLower();
string loginRequest = string.Format("{0}/login.html?hash={1}", url, hash);
fHttpResponseMsg = await fHttpClient.GetAsync(loginRequest);
fHttpRequestMsg = fHttpResponseMsg.RequestMessage;
//get channel listing
string serviceRequest = string.Format("{0}/services/service?method=channel.list&format=json", url);
fHttpResponseMsg = await fHttpClient.GetAsync(serviceRequest);
string json = await fHttpResponseMsg.Content.ReadAsStringAsync();
return true;
}
catch
{
return false;
}
}
public static string CreateMD5(string input)
{
// Use input string to calculate MD5 hash. Cut and paste from Stackoverflow
using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create())
{
byte[] inputBytes = System.Text.Encoding.UTF8.GetBytes(input);
byte[] hashBytes = md5.ComputeHash(inputBytes);
// Convert the byte array to hexadecimal string
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hashBytes.Length; i++)
{
sb.Append(hashBytes[i].ToString("X2"));
}
return sb.ToString();
}
}
Thanks for your help!
JLM