Skip to content

Instantly share code, notes, and snippets.

@chapagainmanoj
Created February 1, 2019 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chapagainmanoj/eb3fcbc041e13fc9b8b5bfa9f35979c2 to your computer and use it in GitHub Desktop.
Save chapagainmanoj/eb3fcbc041e13fc9b8b5bfa9f35979c2 to your computer and use it in GitHub Desktop.
string URLAuth = "https://khalti.com/api/v2/payment/verify/";
string postString = "{\"token\" : \"" + token + "\", \"amount\" : " + amt + " }";
const string authorization_key = "Key test_secret_key_26c3759a78884aecb70f7662e2ab3809";
var request = (HttpWebRequest) WebRequest.Create(URLAuth);
var postData = "{\"token\" : \"" + token + "\", \"amount\" : " + amt + " }";
//var data = Encoding.UTF8.GetBytes(postData);
var data = Encoding.ASCII.GetBytes(postData);
request.Method = "POST";
request.ContentType = "application/json";
request.Headers.Add("Authorization", authorization_key);
request.ContentLength = data.Length;
var stream = request.GetRequestStream();
using (stream)
{
stream.Write(data, 0, data.Length);
}
Console.WriteLine("Request " + request.ContentLength.ToString());
//Console.ReadLine();
try{
var response = (HttpWebResponse)request.GetResponse();
var responseData = new StreamReader(response.GetResponseStream()).ReadToEnd();
//lblKhaltiResponse.Text = responseData;
} catch (WebException e){
using (WebResponse response = e.Response)
{
HttpWebResponse httpResponse = (HttpWebResponse) response;
Console.WriteLine("Error code: {0}", httpResponse.StatusCode);
using (Stream data1 = response.GetResponseStream())
using (var reader = new StreamReader(data1))
{
string text = reader.ReadToEnd();
Console.WriteLine(text);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment