微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

groovy – HTTPBuilder查询参数

我试图理解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
}

我接下来要做的是向查询添加参数.

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'])
}

当我打印resp时,我得到:

java.io.StringReader@16d871c0

参数的代码是否正确?我的输出有什么问题?

我的查询(当我通过浏览器运行时)产生

{"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","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)"],"galleryURL":["http:\/\/thumbs4.sandBox.ebaystatic.com\/m\/mEcUS_FQToCppxHhT12xHvw\/140.jpg"],"viewItemURL":["http:\/\/cgi.sandBox.ebay.com\/Apple-iPhone-3G-8GB-Black-AT-T-Smartphone-MB046LL-A-\/110116107959"],"__value__":"101892398"}],"postalCode":["98102"],"location":["Seattle,WA,"__value__":"0.0"}],"shippingType":["Free"],"handlingTime":["1"]}],"__value__":"149.99"}],"timeLeft":["P26DT22H10M10S"]}],"startTime":["2013-05-08T04:31:25.000Z"],"endTime":["2014-12-29T04:36:25.000Z"],{"itemId":["110089171954"],"galleryURL":["http:\/\/thumbs3.sandBox.ebaystatic.com\/m\/m7btqoH-DYL3EWRCDJgThJg\/140.jpg"],"viewItemURL":["http:\/\/cgi.sandBox.ebay.com\/Apple-iPhone-3G-8GB-Black-Unlocked-Smartphone-\/110089171954"],"timeLeft":["P24DT9H2M20S"]}],"startTime":["2011-05-16T15:23:35.000Z"],"endTime":["2014-12-26T15:28:35.000Z"],"topRatedListing":["false"]}]}],"paginationOutput":[{"pageNumber":["1"],"entriesPerPage":["3"],"totalPages":["564"],"totalEntries":["1691"]}],"itemSearchURL":["http:\/\/shop.sandBox.ebay.com\/i.html?_nkw=iphone+3g&_ddo=1&_ipg=3&_pgn=1"]}]}

解决方法

固定它. contentType不是TEXT.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐