locked
Post request worked in Postman but would not work in C# RRS feed

  • Question

  • User-218090889 posted

    I generated an API call using postman, it worked perfect in Postman, but when I copied the generated code to C# environment it show no response, no error message. below is my code

    var client = new RestClient("https://api.wallets.africa/transfer/bank/account");
    client.Timeout = -1;
    var request = new RestRequest(Method.POST);
    request.AddHeader("Authorization", "Bearer xxxxxxxx ");
    request.AddHeader("Content-Type", "application/json");
    request.AddHeader("Cookie", "__cfduid=d1d00b54377d696360fab484b6a92bb4b1591788299");
    request.AddParameter("application/json", "{\r\n\"SecretKey\": \"xxxxxxxxx\",\r\n\"BankCode\": \"101\",\r\n\"AccountNumber\": \"Acc No\",\r\n\"AccountName\": \"Acc name\",\r\n\"TransactionReference\": \"9821358052\",\r\n\"Amount\": 600.0,\r\n\"Narration\": \"Secure Lot\"\r\n}",  ParameterType.RequestBody);
    IRestResponse response = client.Execute(request);

    please who knows what could be the issue.

    Sunday, June 14, 2020 3:38 AM

Answers

  • User-218090889 posted
    I think I've gotten a fix, I moved the code out of local host to a remote host and it worked fine. I don't know what may cause it not run on local host.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, June 14, 2020 4:02 PM

All replies

  • User409696431 posted

    Did you try using postman's code snippet creator?

    When you have code working in postman, use the code snippet generator: https://learning.postman.com/docs/postman/sending-api-requests/generate-code-snippets/

    For its C# results, it lists the RestSharp library as needed: http://restsharp.org/

    Sunday, June 14, 2020 4:18 AM
  • User-218090889 posted
    I stated that I generated the code using Postman code creator. It worked well in postman environment but when I copied the code to c# environment it returned null and no error message.
    Sunday, June 14, 2020 8:25 AM
  • User409696431 posted

    Did you use the ReSharp library?  Read my earlier message.

    Sunday, June 14, 2020 2:46 PM
  • User-218090889 posted
    I think I've gotten a fix, I moved the code out of local host to a remote host and it worked fine. I don't know what may cause it not run on local host.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, June 14, 2020 4:02 PM