3
NOT FOUND
我的要求是這樣的,但是當我嘗試運行此代碼,我得到這個錯誤:使用RESTClient實現
@Grab(group='org.codehaus.groovy.modules.httpbuilder',module='http-builder', version='0.7')
import groovy.json.JsonOutput
import groovy.json.JsonBuilder
import groovyx.net.http.RESTClient
import static groovyx.net.http.ContentType.*
import groovyx.net.http.HttpResponseException
public PaymentSpring() throws Exception {
def username ='test_XXXXXXXXXXXXXXXXXXXX'
def resp
def https = new RESTClient('https://api.paymentspring.com/api/v1')
https.auth.basic(username,'')
def charge= [
card_owner_name : 'test tset',
card_number : '345829002709133',
card_exp_month:'12',
card_exp_year : '2015',
csc:'999',
amount:'100.00',
email_address:'[email protected]',
send_receipt : true
]
try {
resp = https.post(
path:'/charge',
requestContentType: URLENC,//request content synchronously for the "headers"
headers: ['Content-Type': 'application/x-www-form-urlencoded'],
body:charge
)
} catch(HttpResponseException ex) {
println ex
}
println resp
結果:
groovyx.net.http.HttpResponseException: Not Found
null