首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Moqui -发送一个RESTful sendJSONRequest()到远程URL?

Moqui -发送一个RESTful sendJSONRequest()到远程URL?
EN

Stack Overflow用户
提问于 2015-07-13 08:45:38
回答 2查看 305关注 0票数 0

Moqui -发送一个RESTful sendJSONRequest()到远程URL?

如何使用Moqui向远程URL发送JSON请求?

Moqui中是否存在内置的方法,或者我需要做什么?我需要直接使用JsonBuilder和JsonSlurper groovy类、simpleHttpStringRequest()方法和直接CURL语句来编写脚本吗?(我是Java和Groovy的初学者。)

例如,所需服务:

代码语言:javascript
复制
<service verb="create" noun="RcSupplier">
 <!-- 1. Parse my service's in-parameters and the corresponding remote application parameter field names to needed JSON request body. Also include correct header, authorisation, method, etc. 
 <!-- 2. POST JSON to remote application https://api.xxxxxxxxxxxx.com/api/v1/Suppliers ("Create" Supplier) -->
 <!-- 3. Check response is ok and handle errors --> 
 <!-- 4. GET the Supplier ("find" Supplier) just created on the remote app, to retrieve the primary key (id) that was generated for it by the remote system (either append $filter=code eq 'partyId' or else retrieve all Suppliers as a list to perform our own query) -->
 <!-- 5. Parse the JSON response body received to a map that will be utilised to update my corresponding entity (field: externalId) with the remote primary key value. (note: probably better to use EntityDataLoader to do this later on for check and other functionality?) -->
</service>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-07-14 14:32:58

在Moqui中不需要生成JSON或HTTP客户端代码,有很好的工具可供使用。我首选的JSON工具是Groovy中的类(JsonBuilder或JsonOutput),请参见:

http://docs.groovy-lang.org/latest/html/gapi/groovy/json/package-summary.html

对于HTTP请求,您可以使用StupidWebUtilities.simpleHttpStringRequest()方法,但对于简单、常见的情况,它只是Apache客户端库的一个薄包装器。您也可以直接使用Apache客户端库。

票数 1
EN

Stack Overflow用户

发布于 2015-07-14 02:24:09

看看示例文件夹中的示例,这里也签出了REST示例,但可能对您最有帮助的是Authorize.net的现有应用程序,其中有一个使用XML的远程服务调用的工作示例,因此切换到JSON应该不会太困难。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31378950

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档