AlexJames
Well-known member
- Joined
- Mar 20, 2020
- Messages
- 65
- Programming Experience
- 10+
Hi All
I'm trying to consume a REST API, the issue i'm having is that i need to pass four credentials in the header, it's not just a "basic" authentication with user and password. I keep getting a "400 bad request" error and cant figure out where i'm going wrong. Please could someone point me in the right direction.
I'm trying to consume a REST API, the issue i'm having is that i need to pass four credentials in the header, it's not just a "basic" authentication with user and password. I keep getting a "400 bad request" error and cant figure out where i'm going wrong. Please could someone point me in the right direction.
C#:
public string WebRequestCall(string url)
{
string username = "JohnDoe";
string password = "Testing123";
string collection = "ea85fbf3-5858-4348-bcab-08a8f39ad30c";
string markasread = "False";
var request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
request.Accept = "application/json";
string encodeUser = Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes(username));
string encodePassword = Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes(password));
string encodeCollection = Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes(collection));
string encodeMarkAsRead = Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes(markasread));
request.Headers.Add("Authorization", "Basic " + encodeUser);
request.Headers.Add("Authorization", "Basic " + encodePassword);
request.Headers.Add("Authorization", "Basic " + encodeCollection);
request.Headers.Add("Authorization", "Basic " + encodeMarkAsRead);
var content = string.Empty;
using (var response = (HttpWebResponse)request.GetResponse())
{
using (var stream = response.GetResponseStream())
{
using (var sr = new StreamReader(stream))
{
content = sr.ReadToEnd();
sr.Close();
}
}
}
return content;
}