【问题标题】:How to know sent URL with Grails REST Client Builder Plugin RestBuilder.get()?如何使用 Grails REST Client Builder Plugin RestBuilder.get() 知道发送的 URL?
【发布时间】:2014-10-13 15:03:19
【问题描述】:

现在,我正在开发 Grails 插件,以简化 Grails 应用程序中 Amazon PAAPI 的使用。

这个插件的目标是提供方便的 TagLib 来进行 Amazon PAAPI 操作,如下所示。

<paapi:img idType="ISBN" itemId="4048668161" relationshipType="AuthorityTitle" size="medium" alt="alttext" />

代码将呈现如下。

<img src="http://mediumimageurl.jpg" alt="alttext" />

Taglib 需要意味着连接到 Amazon PAAPI。我为此选择了 Grails REST Client Builder Plugin。

我写了下面的代码。这是服务方法。

def itemLookup(
            String condition,
            String idType,
            String itemId,
            String merchantId,
            String offerPage,
            String relatedItemsPage,
            String relationshipType,
            String reviewPage,
            String reviewSort,
            String searchIndex,
            String tagPage,
            String tagsPerPage,
            String tagSort,
            String variationPage,
            ResponseGroup responseGroup) {
        def associateId = grailsApplication.config.grails.plugin.foo.amazonpaapi.associateId
        def paapiAccessKey = grailsApplication.config.grails.plugin.foo.amazonpaapi.paapiAccessKey
        def paapiSecretAccessKey = grailsApplication.config.grails.plugin.foo.amazonpaapi.paapiSecretAccessKey

        def rest = new RestBuilder()
        def resp = rest.get(
                "http://ecs.amazonaws.com/onca/xml",
                [
                    Service:'AWSECommerceService',
                    AWSAccessKeyId:paapiAccessKey,
                    AssociateTag:associateId,
                    Operation:'ItemLookup',
                    Condition:condition,
                    IdType:idType,
                    ItemId:itemId,
                    MerchantId:merchantId,
                    OfferPage:offerPage,
                    RelatedItemsPage:relatedItemsPage,
                    RelationshipType:relationshipType,
                    ReviewPage:reviewPage,
                    ReviewSort:reviewSort,
                    SearchIndex:searchIndex,
                    Tagage:tagPage,
                    TagsPerPage:tagsPerPage,
                    TagSort:tagSort,
                    VariationPage:variationPage,
                    ResponseGroup:responseGroup.getLabel()
                ]) {
            accept "application/xml"
        }
        return resp.xml
    }

代码失败。

我得到了以下结果。它已输入resp.txt

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html> <head> <title>400 Bad Request</title> </head> <body> <div align=center> <a href="http://www.amazon.com/"><img src="http://g-images.amazon.com/images/G/01/icons/amazon-logo.gif" width=140 height=30 alt="Amazon.com" border=0></a><br> </div> <h1>Bad Request</h1> <p>Parameter Operation is missing</p> </body> </html>

问题在于您不知道为什么会发生这种情况。

我想知道从RestBuilder.get() 发送到 Amazon PAAPI 的 URL。我没找到。

你有什么办法知道怎么做吗?

【问题讨论】:

    标签: grails amazon


    【解决方案1】:

    自行解决。

    最后,我找不到知道 REST 请求 url 的方法。

    但是,这个错误已经解决了。我在来自 Amazon 的请求中发现错误消息

    <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html> <head> <title>400 Bad Request</title> </head> <body> <div align=center> <a href="http://www.amazon.com/"><img src="http://g-images.amazon.com/images/G/01/icons/amazon-logo.gif" width=140 height=30 alt="Amazon.com" border=0></a><br> </div> <h1>Bad Request</h1> <p>Parameter Operation is missing</p> </body> </html>
    
    Parameter Operation is missing
    

    我可以像下面这样解决这个错误。

    def resp = rest.get('http://ecs.amazonaws.com/onca/xml?Operation={Operation}') {
            urlVariables Operation:'ItemLookup'
        }
    

    好像已经返回了错误,因为没有必要的操作参数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-22
      相关资源
      最近更新 更多