Hi,
Can anyone have an example of an established connection to DHIS2 using C# HttpWebRequest or WebClient methods?
I have written this method and all i get are errors when establishing the connection.
private void ConnectDHIS()
{
string uname = “admin”, pwd = “district”;
string formattedUrl = “https://apps.dhis2.org/demo/dhis-web-commons/security/login.action?authOnly=true ”;
string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(uname + “:” + pwd));
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(formattedUrl);
// request.PreAuthenticate = true;
request.Headers[HttpRequestHeader.Authorization] = string.Format(“Basic {0}”, credentials);
// request.Headers[“Authorization”] = "Basic " + credentials;
//request.Headers.Add (“Authorization”,"Basic " + credentials);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
txtresponse.Text = response.ResponseUri.ToString();
}
The above code does not work even for my own local instance of DHIS2.
Charles.
morten
(Morten Hansen)
20 August 2015 07:01
2
Hi
Why are you making basic auth request to our form login processor? when you are using basic auth, just go directly to the url you want, i.e. /api/dataElements.json
Also, it would be helpful to know exactly which errors you get
···
On Thu, Aug 20, 2015 at 1:41 PM, charles waka charlwak@gmail.com wrote:
Hi,
Can anyone have an example of an established connection to DHIS2 using C# HttpWebRequest or WebClient methods?
I have written this method and all i get are errors when establishing the connection.
private void ConnectDHIS()
{
string uname = “admin”, pwd = “district”;
string formattedUrl = “https://apps.dhis2.org/demo/dhis-web-commons/security/login.action?authOnly=true ”;
string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(uname + “:” + pwd));
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(formattedUrl);
// request.PreAuthenticate = true;
request.Headers[HttpRequestHeader.Authorization] = string.Format(“Basic {0}”, credentials);
// request.Headers[“Authorization”] = "Basic " + credentials;
//request.Headers.Add (“Authorization”,"Basic " + credentials);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
txtresponse.Text = response.ResponseUri.ToString();
}
The above code does not work even for my own local instance of DHIS2.
Charles.
Mailing list: https://launchpad.net/~dhis2-users
Post to : dhis2-users@lists.launchpad.net
Unsubscribe : https://launchpad.net/~dhis2-users
More help : https://help.launchpad.net/ListHelp
–
Morten
Hi Charles,
Can you share the error message. I think WebClient it’s easy to use for calling a web API in c#.
Cheers,
···
On Aug 20, 2015 7:41 AM, “charles waka” charlwak@gmail.com wrote:
Hi,
Can anyone have an example of an established connection to DHIS2 using C# HttpWebRequest or WebClient methods?
I have written this method and all i get are errors when establishing the connection.
private void ConnectDHIS()
{
string uname = “admin”, pwd = “district”;
string formattedUrl = “https://apps.dhis2.org/demo/dhis-web-commons/security/login.action?authOnly=true ”;
string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(uname + “:” + pwd));
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(formattedUrl);
// request.PreAuthenticate = true;
request.Headers[HttpRequestHeader.Authorization] = string.Format(“Basic {0}”, credentials);
// request.Headers[“Authorization”] = "Basic " + credentials;
//request.Headers.Add (“Authorization”,"Basic " + credentials);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
txtresponse.Text = response.ResponseUri.ToString();
}
The above code does not work even for my own local instance of DHIS2.
Charles.
Mailing list: https://launchpad.net/~dhis2-users
Post to : dhis2-users@lists.launchpad.net
Unsubscribe : https://launchpad.net/~dhis2-users
More help : https://help.launchpad.net/ListHelp
I did some further research based on what Morten had suggested and I can manipulate the data from my end (on the local instance of DHIS2 we have).
Thanks for your help and suggestions.
···
On Thu, Aug 20, 2015 at 10:06 AM, riddy ndoma riddyndoma@gmail.com wrote:
Hi Charles,
Can you share the error message. I think WebClient it’s easy to use for calling a web API in c#.
Cheers,
On Aug 20, 2015 7:41 AM, “charles waka” charlwak@gmail.com wrote:
Hi,
Can anyone have an example of an established connection to DHIS2 using C# HttpWebRequest or WebClient methods?
I have written this method and all i get are errors when establishing the connection.
private void ConnectDHIS()
{
string uname = “admin”, pwd = “district”;
string formattedUrl = “https://apps.dhis2.org/demo/dhis-web-commons/security/login.action?authOnly=true ”;
string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(uname + “:” + pwd));
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(formattedUrl);
// request.PreAuthenticate = true;
request.Headers[HttpRequestHeader.Authorization] = string.Format(“Basic {0}”, credentials);
// request.Headers[“Authorization”] = "Basic " + credentials;
//request.Headers.Add (“Authorization”,"Basic " + credentials);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
txtresponse.Text = response.ResponseUri.ToString();
}
The above code does not work even for my own local instance of DHIS2.
Charles.
Mailing list: https://launchpad.net/~dhis2-users
Post to : dhis2-users@lists.launchpad.net
Unsubscribe : https://launchpad.net/~dhis2-users
More help : https://help.launchpad.net/ListHelp