我试图理解HTTP Builder的简化GET.我成功地使用类似于REST GET请求的简单GET请求.
def client = new HTTPBuilder('http://pokeapi.co')
def resp = client.get(path: '/api/v1/pokemon/1')
static void main(String[] args){
def h = new HTTP()
print h.resp.name
}
Run Code Online (Sandbox Code Playgroud)
我接下来要做的是为查询添加参数.
def client = new HTTPBuilder('http://svcs.sandbox.ebay.com')
def resp = client.get(path: '/services/search/FindingService/v1',
contentType: TEXT,
query:[
'SECURITY-APPNAME': APP_ID,
'OPERATION-NAME':'findItemsByKeywords',
'SERVICE_VERSION':'1.0.0',
'RESPONSE-DATA-FORMAT':'JSON',
'callback':'_cb_findItemsByKeywords',
'REST-PAYLOAD': '',
'keywords':'iphone 3g',
'paginationInput.entriesPerPage': '3'])
}
Run Code Online (Sandbox Code Playgroud)
当我打印时resp,我得到:
java.io.StringReader@16d871c0
Run Code Online (Sandbox Code Playgroud)
参数的代码是否正确?我的输出有什么问题?
我的查询(当我通过浏览器运行时)产生
{"findItemsByKeywordsResponse":[{"ack":["Success"],"version":["1.13.0"],"timestamp":["2014-12-02T06:26:15.869Z"],"searchResult":[{"@count":"3","item":[{"itemId":["110089183401"],"title":["Apple iPhone 3G - 8GB - Black (Unlocked) Smartphone"],"globalId":["EBAY-US"],"primaryCategory":[{"categoryId":["9355"],"categoryName":["Cell Phones & Smartphones"]}],"galleryURL":["http:\/\/thumbs2.sandbox.ebaystatic.com\/m\/mI_iSJ1zmYlidmuoLh9Pndw\/140.jpg"],"viewItemURL":["http:\/\/cgi.sandbox.ebay.com\/Apple-iPhone-3G-8GB-Black-Unlocked-Smartphone-\/110089183401"],"productId":[{"@type":"ReferenceID","__value__":"100014203"}],"paymentMethod":["PayPal"],"autoPay":["false"],"postalCode":["95125"],"location":["San Jose,CA,USA"],"country":["US"],"shippingInfo":[{"shippingServiceCost":[{"@currencyId":"USD","__value__":"2.5"}],"shippingType":["Flat"],"shipToLocations":["US"],"expeditedShipping":["false"],"oneDayShippingAvailable":["false"],"handlingTime":["3"]}],"sellingStatus":[{"currentPrice":[{"@currencyId":"USD","__value__":"100.0"}],"convertedCurrentPrice":[{"@currencyId":"USD","__value__":"100.0"}],"sellingState":["Active"],"timeLeft":["P25DT9H19M59S"]}],"listingInfo":[{"bestOfferEnabled":["false"],"buyItNowAvailable":["false"],"startTime":["2011-05-17T15:41:14.000Z"],"endTime":["2014-12-27T15:46:14.000Z"],"listingType":["FixedPrice"],"gift":["false"]}],"returnsAccepted":["true"],"condition":[{"conditionId":["1000"],"conditionDisplayName":["New"]}],"isMultiVariationListing":["false"],"topRatedListing":["false"]},{"itemId":["110116107959"],"title":["Apple iPhone 3G - 8GB - Black (AT&T) Smartphone (MB046LL\/A)"],"globalId":["EBAY-US"],"primaryCategory":[{"categoryId":["9355"],"categoryName":["Cell …Run Code Online (Sandbox Code Playgroud)