I have this sample code in PHP I'm trying to convert to ASP.NET to call an API web service
<?php // Replace the strings with your API credentials located in Admin > OfficeAutoPilot API Instructions and Key Manager$app_id = "xxx";$api_key = "yyy";$reqType= "list_gateways";$postargs = "appid=".$app_id."&key=".$api_key."&reqType=".$reqType;$request = "https://api.ontraport.com/payments.php";$session = curl_init($request); curl_setopt ($session, CURLOPT_POST, true); curl_setopt ($session, CURLOPT_POSTFIELDS, $postargs); curl_setopt($session, CURLOPT_HEADER, false); curl_setopt($session, CURLOPT_RETURNTRANSFER, true);$response = curl_exec($session); curl_close($session); echo $response; ?>
It returns the proper result: [{"id":59669,"name":"PayPal"},{"id":59670,"name":"Test"},{"id":63109,"name":"PayPal Payments Pro"},{"id":63142,"name":"PayPal Payments Pro"},{"id":63143,"name":"PayPal Payments Pro"}]
Here's the ASP.NET conversion
<%@ Page Title="Test Page" Language="C#" %><%@ Import Namespace="System.Net" %><%@ Import Namespace="System.IO" %><script runat="server"> protected override void OnLoad(EventArgs e) { HttpWebRequest Request = (HttpWebRequest)WebRequest.Create("https://api.ontraport.com/payments.php"); Request.Method = "POST"; // Call method and get result using (Stream rs = Request.GetRequestStream()) { byte[] RequestBytes = Encoding.UTF8.GetBytes("appid=xxx&key=yyy&reqType=list_gateways"); rs.Write(RequestBytes, 0, RequestBytes.Length); } // Read server response. HttpWebResponse Response = (HttpWebResponse)Request.GetResponse(); Stream ResponseStream = Response.GetResponseStream(); StreamReader reader = new StreamReader(ResponseStream); string ResponseString = reader.ReadToEnd(); Page.Response.Write(ResponseString); } </script>
This, instead, returns this error message: "Oops! This is the API address where you send api commands, please read the manualhere to figure out how to get started using the API!"
I'm sending in the exact same request but get a different answer. Who can spot the mistake?