Asp.net 如何使用C#.Net发布此(Payjunction)请求

Asp.net 如何使用C#.Net发布此(Payjunction)请求,asp.net,http,c#-4.0,request,payjunction,Asp.net,Http,C# 4.0,Request,Payjunction,这就是我尝试过的: curl -X POST -u "pj-ql-01:pj-ql-01p" -H "Accept: application/json" -H "X-PJ-Application-Key: YOUR_LABS_APP_KEY" \ -d "action=CHARGE" \ -d "cardNumber=4444333322221111" \ -d "cardExpMonth=01" \ -d "cardExpYear=2020" \ -d "amountBase=3.00" \

这就是我尝试过的:

curl -X POST -u "pj-ql-01:pj-ql-01p" -H "Accept: application/json" -H "X-PJ-Application-Key: YOUR_LABS_APP_KEY" \
-d "action=CHARGE" \
-d "cardNumber=4444333322221111" \
-d "cardExpMonth=01" \
-d "cardExpYear=2020" \
-d "amountBase=3.00" \
"https://api.payjunctionlabs.com/transactions"
UTF8Encoding enc=新的UTF8Encoding();
字符串usernamePassword=“pj-ql-01”+”:“+”pj-ql-01p”;
字符串url=”https://api.payjunctionlabs.com/transactions";
KeyValuePair Credential=新的KeyValuePair(“授权”、“基本”+Convert.ToBase64String(enc.GetBytes(usernamePassword)));
KeyValuePair HdrAppKey=新的KeyValuePair(“X-PJ-Application-Key”,“您的密钥”);
string postData=“action=CHARGE&cardNumber=444433332221111&cardExpMonth=01&cardExpYear=2020&amountBase=3.00&cardCvv=999”;
字节[]postDataBytes=enc.GetBytes(postData);
HttpWebRequest myReq=(HttpWebRequest)WebRequest.Create(url);
myReq.Method=“POST”;
myReq.Headers[Credential.Key]=Credential.Value;
myReq.Headers[HdrAppKey.Key]=HdrAppKey.Value;
myReq.KeepAlive=true;
myReq.Accept=“应用程序/json”;
myReq.MediaType=“应用程序/json”;
myReq.ContentType=“application/x-www-form-urlencoded;charset=UTF-8”;
myReq.ContentLength=postDataBytes.Length;
Stream myReqStream=myReq.GetRequestStream();
myReqStream.Write(postDataBytes,0,postDataBytes.Length);
尝试
{
b串;
使用(var response=myReq.GetResponse())
{
使用(var reader=newstreamreader(response.GetResponseStream())
{
b=reader.ReadToEnd();
}
}
答复.书面答复(b);
}
捕获(例外情况除外)
{
响应。写入(例如消息);
回答。写(“
”); 响应。写入(例如StackTrace); 回答。写(“
”); test(); }
代码来源:
UTF8Encoding enc = new UTF8Encoding();
    string usernamePassword = "pj-ql-01" + ":" + "pj-ql-01p";
    string url = "https://api.payjunctionlabs.com/transactions";

    KeyValuePair<string, string> Credential = new KeyValuePair<string, string>("Authorization", "Basic " + Convert.ToBase64String(enc.GetBytes(usernamePassword)));
    KeyValuePair<string, string> HdrAppKey = new KeyValuePair<string, string>("X-PJ-Application-Key", "your key");

    string postData= "action=CHARGE&cardNumber=4444333322221111&cardExpMonth=01&cardExpYear=2020&amountBase=3.00&cardCvv=999";
    byte[] postDataBytes = enc.GetBytes(postData);
    HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(url);

    myReq.Method = "POST";
    myReq.Headers[Credential.Key] = Credential.Value;
    myReq.Headers[HdrAppKey.Key] = HdrAppKey.Value;

    myReq.KeepAlive = true;
    myReq.Accept = "application/json";
    myReq.MediaType = "application/json";
    myReq.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
    myReq.ContentLength = postDataBytes.Length;
    Stream myReqStream = myReq.GetRequestStream();
    myReqStream.Write(postDataBytes, 0, postDataBytes.Length);
    try
    {
        string b;
        using (var response = myReq.GetResponse())
        {
            using (var reader = new StreamReader(response.GetResponseStream()))
            {
                b = reader.ReadToEnd();
            }
        }
        Response.Write(b);
    }
    catch (Exception ex)
    {
        Response.Write(ex.Message);
        Response.Write("</br>");
        Response.Write(ex.StackTrace);
        Response.Write("</br>");
        test();

    }