0

Calling Flipkart API in ASP.NET. Here is my code, however I get an error

WebException: The request was aborted: Could not create SSL/TLS secure channel.

Can someone please help me with my code?

string apiUrl = "https://api.flipkart.net/sellers/v3/orders";
string apiKey = "";

// Create HttpClient instance
HttpClient client = new HttpClient();

// Set API key in the request headers
client.DefaultRequestHeaders.Add("Authorization","apiKey ");

// Create the order payload
string orderPayload = "{ \"productId\": \"OD327976981909300\", \"quantity\": 1 }";

// Create the HTTP content
var content = new StringContent(orderPayload, Encoding.UTF8, "application/json");

try
{
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
    // Send the POST request to place the order
    HttpResponseMessage response = await client.PostAsync(apiUrl, content);

    // Check if the request was successful
    if (response.IsSuccessStatusCode)
    {
        // Order placed successfully
        Console.WriteLine("Order placed successfully.");
    }
    else
    {
        // Failed to place the order
        Console.WriteLine("Failed to place the order. Error: " + response.ReasonPhrase);
    }
}
catch (Exception ex)
{
    // An error occurred
    Console.WriteLine("An error occurred while placing the order. Error: " + ex.Message);
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

0 Answers0