Rest API always return 401 status code
-
I am working with Nasdaq Fund Network Data Service first time. i am calling their one of the API where passing user id,pwd and access key but always getting 401 status code. i am not able to figure out what is wrong in my http call. please some one have a look at the code and tell me where i made the mistake for which i am getting 401 status code instead of right response. here is my sample code where i could not share actual credentials and access key.
string url = "https://nfn.nasdaq.com/servicecall/tempsession";
Uri u = new Uri(url);string username = "test1";
string password = "test1";
string accessKey = "my key";var payload = new Dictionary
{
{"username", username},
{"password", password},
{ "accesskey", accessKey}
};string strPayload = JsonConvert.SerializeObject(payload);
HttpContent c = new StringContent(strPayload, Encoding.UTF8, "application/x-www-form-urlencoded");var response = string.Empty;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11;
using (var client = new HttpClient())
{
//client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessKey);
//client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Authorization", "Bearer " + accessKey);HttpRequestMessage request = new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = u,
Content = c
};var result = client.SendAsync(request).Result;
if (result.IsSuccessStatusCode)
{
response = result.StatusCode.ToString();
}
} -
I am working with Nasdaq Fund Network Data Service first time. i am calling their one of the API where passing user id,pwd and access key but always getting 401 status code. i am not able to figure out what is wrong in my http call. please some one have a look at the code and tell me where i made the mistake for which i am getting 401 status code instead of right response. here is my sample code where i could not share actual credentials and access key.
string url = "https://nfn.nasdaq.com/servicecall/tempsession";
Uri u = new Uri(url);string username = "test1";
string password = "test1";
string accessKey = "my key";var payload = new Dictionary
{
{"username", username},
{"password", password},
{ "accesskey", accessKey}
};string strPayload = JsonConvert.SerializeObject(payload);
HttpContent c = new StringContent(strPayload, Encoding.UTF8, "application/x-www-form-urlencoded");var response = string.Empty;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11;
using (var client = new HttpClient())
{
//client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessKey);
//client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Authorization", "Bearer " + accessKey);HttpRequestMessage request = new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = u,
Content = c
};var result = client.SendAsync(request).Result;
if (result.IsSuccessStatusCode)
{
response = result.StatusCode.ToString();
}
}I think there's more to it than sending some raw login information. [GitHub - Nasdaq/NasdaqCloudDataService-SDK-Java: Nasdaq Cloud Data Service (NCDS) provides a modern and efficient method of delivery for realtime exchange data and other financial information. This repository provides an SDK for developing applicatio](https://github.com/Nasdaq/NasdaqCloudDataService-SDK-Java)
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
-
I think there's more to it than sending some raw login information. [GitHub - Nasdaq/NasdaqCloudDataService-SDK-Java: Nasdaq Cloud Data Service (NCDS) provides a modern and efficient method of delivery for realtime exchange data and other financial information. This repository provides an SDK for developing applicatio](https://github.com/Nasdaq/NasdaqCloudDataService-SDK-Java)
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I