prolog grails中不允许XML错误

时间:2015-02-01 14:26:16

标签: xml grails

我在Curl命令上有以下内容:

curl -i -H "Content-Type: text/xml" -d '<sample:WIB xmlns:sample="www.sample.com"><sample:Customer><sample:Catalog_ID>01</sample:Catalog_ID><sample:Shop_ID>01</sample:Shop_ID></sample:Customer></sample:WIB>' http://localhost:8080/app/API/

我的Grails控制器是:

def index() {
    String xml = request.XML.toString();
    def workXml = new XmlSlurper().parseText(xml)
}

解析时出错 我也试过这个:

def workXml = new XmlSlurper().parseText(xml).declareNamespace(sample: 'sample')

我得到同样的错误:

这是堆栈跟踪:

Message: Content is not allowed in prolog.
Line | Method
->>   10 | index     in app.APIController$$EP3387M0
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
|    198 | doFilter  in grails.plugin.cache.web.filter.PageFragmentCachingFilter
|     63 | doFilter  in grails.plugin.cache.web.filter.AbstractFilter
|     53 | doFilter  in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
|     49 | doFilter  in grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter
|     82 | doFilter  in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run . . . in java.lang.Thread

1 个答案:

答案 0 :(得分:3)

您使用了错误的curl选项 - -d选项需要name=value对,并将其视为来自浏览器的表单帖子。如果您想要完全按照命令行发送数据,则应使用--data-binary代替。

顺便说一下,request.XML已经被解析了 - 它GPathResult与您从XmlSlurper得到的相同,所以没有必要尝试转换它回到一根绳子再次啜饮它。