0
string xml = "<?xml version='1.0'? encoding='UTF-8'?><!DOCTYPE paymentService PUBLIC '-//WorldPay//DTD WorldPay PaymentService v1//EN''http://dtd.worldpay.com/paymentService_v1.dtd'><paymentService version='1.4' merchantCode='MYMERCHANTCODE'><submit><order orderCode='RecurringOrderCode'><description>Monthly subscription.</description><amount value='1399' currencyCode='EUR' exponent='2' /><orderContent>Your Original Order Content</orderContent> <paymentDetails><VISA-SSL> <cardNumber>4444333322221111</cardNumber><expiryDate> <date month='09' year='2019'/> </expiryDate> <cardHolderName>J. Shopper</cardHolderName><cvc>123</cvc> <cardAddress> <address> <street>47A Queensbridge Rd</street><postalCode>CB94BQ</postalCode><city>GB</city><countryCode>GB</countryCode><telephoneNumber>+44</telephoneNumber> </address> </cardAddress> </VISA-SSL> <session shopperIPAddress='100.100.100.100' id='0215ui8ib1' /> </paymentDetails></order></submit></paymentService>";
        string url = "https://secure-test.worldpay.com/jsp/merchant/xml/paymentService.jsp";
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
        //string s = "id="+Server.UrlEncode(xml);
        byte[] requestBytes = System.Text.Encoding.ASCII.GetBytes(xml);
        req.Method = "POST";
        req.ContentType = "text/xml;charset=utf-8";
        req.ContentLength = requestBytes.Length;
        Stream requestStream = req.GetRequestStream();
        requestStream.Write(requestBytes, 0, requestBytes.Length);
        requestStream.Close();
        HttpWebResponse res = (HttpWebResponse)req.GetResponse();
        StreamReader sr = new StreamReader(res.GetResponseStream(), System.Text.Encoding.Default);
        string backstr = sr.ReadToEnd();
        sr.Close();
        res.Close();
        return View();

このコードを使用して Worldpay 支払いゲートウェイ API を統合しています HttpWebResponse res = (HttpWebResponse)req.GetResponse();

エラーは -401 認証が必要です

4

1 に答える 1

1

資格情報をリクエストに追加する必要があります。おそらく HTTP 基本認証です。次のようにできます:

req.Headers[HttpRequestHeader.Authorization] = "Basic " + 
    Convert.ToBase64String(Encoding.ASCII.GetBytes(<username> + ":" + <password>));
于 2013-05-16T08:21:19.607 に答える