0

I want to call REST Api from Asp.net application in order to integrate with NCB bank, they provide me with some test parameters like:

  1. AccessCode
  2. Merchant Id
  3. Secure Hash code

I've tried the below code but it doesn't work properly it throw 404 http error code.

 private const string URL="https://migs.mastercard.com.au/vpcpay";
 private const string urlParameters = @"{""object"":{""vpc_AccessCode"":""000000"",""vpc_Version"":""0""};}";

 HttpClient client = new HttpClient();
 client.BaseAddress = new Uri(URL);

 //Add an Accept header for JSON format.
 client.DefaultRequestHeaders.Accept.Add(
 new MediaTypeWithQualityHeaderValue("application/json"));

 HttpResponseMessage response = client.GetAsync(urlParameters).Result;


   if (response.IsSuccessStatusCode)
    {
      // Parse the response body. Blocking!
      var dataObjects = response.Content.ReadAsAsync<IEnumerable<DataObject>>().Result;
         foreach (var d in dataObjects)
          {
            Console.WriteLine("{0}", d.Name);
          }
    }
   else
    {
      Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
    }
Dii
  • 147
  • 13

2 Answers2

0

I think it should be using a POST, not a GET. Use PostAsync instead of GetAsync.

Ricardo Peres
  • 13,724
  • 5
  • 57
  • 74
0

Googling around I found this gist which seems to be what you are after with a whole lot of the plumbing already done for you.

https://gist.github.com/samnaseri/2211309

Murray Foxcroft
  • 12,785
  • 7
  • 58
  • 86