locked
HttpRequestException in mscorlib.dll thrown when running PostSync Method in ASP.NET MVC. RRS feed

  • Question

  • static async Task<string> ApiCallAsync(string token)
            {
                //should return the response token
                String response = "";
                var url = "https://api.ciscospark.com/v1/jwt/login";
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
                try
                {   //requesting a guest token
                  //  httpClient.DefaultRequestHeaders.ExpectContinue = false;
                    var responseMessage = await httpClient.PostAsync(url, null); //calls the post http request- currently throwing exxception
                    var responseString = await responseMessage.Content.ReadAsStringAsync();
                    var JSONObj = new JavaScriptSerializer().Deserialize<Dictionary<string, string>>(responseString);
                    response = JSONObj["token"];
    
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"There was an exception: {ex.ToString()}");
                }
    
                return response;
            }

    We solved the issue adding a a line of SSL.
    Thursday, April 18, 2019 12:33 AM

All replies

  • Hello,

    Please clean up your post, put the question first then the code using a code block.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Thursday, April 18, 2019 12:52 AM
  • The post would be of benefit if it were posted to the ASP.NET MVC forum.

    https://forums.asp.net/

    Thursday, April 18, 2019 5:43 AM
  • Hi

    Thank you for posting here.

    Since this thread is related to asp.net MVC, you could post in the following forum.

    https://forums.asp.net/1146.aspx

    The Visual C# forum discusses and asks questions about the C# programming language, IDE, libraries, samples, and tools.

    Best regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, April 18, 2019 8:08 AM