-
-
Save chapagainmanoj/eb3fcbc041e13fc9b8b5bfa9f35979c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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