Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Rest API always return 401 status code

Rest API always return 401 status code

Scheduled Pinned Locked Moved .NET (Core and Framework)
jsoncomsysadminsecurityquestion
3 Posts 2 Posters 16 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mou_kol
    wrote on last edited by
    #1

    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();
    }
    }

    L 1 Reply Last reply
    0
    • M Mou_kol

      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();
      }
      }

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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

      M 1 Reply Last reply
      0
      • L Lost User

        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

        M Offline
        M Offline
        Mou_kol
        wrote on last edited by
        #3

        i am looking for c# related call.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups