Groovy API中的pin支付密钥位置



我在pin.net.au做pin支付的API,我遇到了一些错误,就像你在底部看到的

`@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder'`,` version='0.5.0-RC2' )
    import groovyx.net.http.*
    import groovyx.net.http.HttpResponseDecorator
    import groovyx.net.http.RESTClient
    import static groovyx.net.http.ContentType.*
    import groovyx.net.http.HttpResponseException
    import groovy.swing.SwingBuilder
    import javax.swing.JFrame
    import wslite.http.auth.*
    class Customers {
        Customers(){
            def rst = new RESTClient( 'https://test-api.pin.net.au/1/')
    rst.auth.basic 'mySecretKey',''
            def res = rst.post( path: 'customers'){
                type ContentType.XML
                xml {
                    cards{
                        email('pk_qTj9Umqmlf3o7lfa6F9nWw')
                        card[expiry_month]('12')
                        card[expiry_year]('2015')
                        card[cvc]('123')
                        card[name]('patrick pl')
                        card[address_line1]('23 frfds')
                        card[address_city]('Angeles')
                        card[address_postcode]('2009')
                        card[address_state]('ph')
                        card[address_country]('Philippines')
                    }
                }
            }
        }
        public static void main(String []args){
            new Customers()
        }
    }

当我运行代码时,错误是

   May 12, 2014 1:07:35 PM org.apache.http.impl.client.DefaultRequestDirector handleResponse
    WARNING: Authentication error: Unable to respond to any of these challenges: {}
    Caught: groovyx.net.http.HttpResponseException: Authorization Required
    groovyx.net.http.HttpResponseException: Authorization Required
        at groovyx.net.http.RESTClient.defaultFailureHandler(RESTClient.java:240)
        at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:475)
        at groovyx.net.http.HTTPBuilder.post(HTTPBuilder.java:335)
        at groovyx.net.http.HTTPBuilder$post.call(Unknown Source)
        at PinPayment.Customers.<init>(Customers.groovy:16)
        at PinPayment.Customers.main(Customers.groovy:39)

我怎么能使身份验证工作的代码是可运行的??这里是文档的链接pin.net.au

文档表明需要基本的HTTP认证。

对Pin Payments API的调用必须使用HTTP basic进行身份验证身份验证,使用您的API密钥作为用户名,以及一个空白字符串作为密码。
因此:

def rst = new RESTClient( 'https://test-api.pin.net.au/1/' )
rst.auth.basic 'secretAPIKeyHereAsString', ''

我在这里找到了这个api的正确代码def http = new RESTClient('https://test-api.pin.net.au/1/') http.headers['Authorization'] = 'Basic '+"tWqZl0MHsg5nUQdB6czrDQ:".getBytes('iso-8859-1').encodeBase64()

最新更新