RSS

Navigation



Quick Search'''



C#.NET HTTP FORM POST

RSS
//Define a command object for populating command parameters

PK_PaymentKey_Activate_Command PK_Command = new PK_PaymentKey_Activate_Command();

//Build the command  to send to the PaymentKeys Application Framework

PK_Command.command = "paymentkey.activate";

PK_Command.version = "1.0";

PK_Command.api_call_id = Guid.NewGuid.ToString;

PK_Command.paymentkey = "v1111_00000_00000_00000.pk";

//Serialize the command object

System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();

string api_call = serializer.Serialize(PK_Command);

//Create HMACSHA1 signature hash for the JSON command string using the GatewayCode

System.Security.Cryptography.HMACSHA1 sha1 = new System.Security.Cryptography.HMACSHA1();

//   Specify the GatewayCode secret key

sha1.Key = System.Text.Encoding.UTF8.GetBytes("PK_Demo");
//   Convert the JSON command string to a byte array
byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(api_call);
//   Generate the hash signature
string api_sig = Convert.ToBase64String(sha1.ComputeHash(byteArray));

//Submit the REST-based HTTP Request to the PaymentKeys Application Framework gateway
string PostURL = "https://www.paymentkeys.com/api.rest/appserver";

HttpWebRequest http_request = (HttpWebRequest)WebRequest.Create(PostURL);

//   Define the data to post

StringBuilder postData = new StringBuilder();

postData.Append("api_KeyID=PaymentKeys_Demo.pk");

postData.Append("&api_sig=" + Server.UrlEncode(api_sig));

postData.Append("&api_call=" + Server.UrlEncode(api_call));

postData.Append("&api_output=json");

//   Encode the post data into a byte array

System.Text.UTF8Encoding encodedData = new System.Text.UTF8Encoding();

byte[] postData_byteArray = encodedData.GetBytes(postData.ToString);

//   Set http request headers

http_request.Method = "POST";

http_request.ContentType = "application/x-www-form-urlencoded";

http_request.ContentLength = postData_byteArray.Length;

//   Stream the post data to the PaymentKeys application gateway
Stream request_stream = http_request.GetRequestStream();

request_stream.Write(postData_byteArray, 0, postData_byteArray.Length);

request_stream.Close();

//   Process the response

HttpWebResponse http_response = null;

StreamReader response_stream = null;

string JSON_Response = string.Empty;
try
{

http_response = (HttpWebResponse)http_request.GetResponse();
response_stream = new StreamReader(http_response.GetResponseStream(), Encoding.UTF8);
JSON_Response = response_stream.ReadToEnd();
}
catch (WebException Ex)
{
//Handle http communication errors here
}
finally
{
if ((http_response != null))
{
http_response.Close();
http_response = null;
}
}

//Deserialize JSON response string into response object
if (!(JSON_Response == string.Empty))
{

PK_PaymentKeyAdmin_Response PK_Response = default(PK_PaymentKeyAdmin_Response);
PK_Response = serializer.Deserialize(JSON_Response);

//Parse the Response per your application and policy rules
switch (PK_Response.status)
{
case ...

}


 

ScrewTurn Wiki version 5.2.0.8. Some of the icons created by FamFamFam.