我必须与所谓的REST API集成,它根本不是RESTFul。要向特定的GET请求添加更多数据,我必须在URL中发送一个3d数组(丑陋!!)。有没有人知道如何使用Apache HTTP客户端v4.0.1?
以下是PHP中的示例:
$arrArguments['saleData'] = array();
$arrArguments['saleData']['invoiceDate'] = 'abcdef';
$arrArguments['saleData']['deliveryDate'] = 'abcdef';
$arrArguments['saleData']['orderData'] = array();
$arrArguments['saleData']['orderData'][0] = array();
$arrArguments['saleData']['orderData'][0]['productId'] = 'abcdef';
$arrArguments['saleData']['orderData'][0]['description'] = 'abcdef';
$arrArguments['saleData']['orderData'][0]['price'] = 18819;
$arrArguments['saleData']['orderData'][0]['quantity'] = 24389;
$arrArguments['saleData']['orderData'][0]['vatCode'] = 'abcdef';;;;
答案 0 :(得分:0)
请试试这个
$arrArguments['saleData'] = array();
$arrArguments['saleData']['orderData'] = array();
$arrArguments['saleData']['orderData'][0] = array();
$arrArguments['saleData']['invoiceDate'] = 'abcdef';
$arrArguments['saleData']['deliveryDate'] = 'abcdef';
$arrArguments['saleData']['orderData'][0]['productId'] = 'abcdef';
$arrArguments['saleData']['orderData'][0]['description'] = 'abcdef';
$arrArguments['saleData']['orderData'][0]['price'] = 18819;
$arrArguments['saleData']['orderData'][0]['quantity'] = 24389;
$arrArguments['saleData']['orderData'][0]['vatCode'] = 'abcdef';
$restUrl ='/saleData/orderData';
new Ajax.Request("<?php echo $this->getUrl($restUrl) ?>", {
method: 'Post',
parameters: {
"saledata" :$arrArguments['saleData']
},
onComplete: function(response) {
console.log(response);
}
});
如果您使用java / php作为后端语言,则获取请求参数以获取数据。
for java: -
@RequestMapping(value = "/saleData/orderData", method = RequestMethod.GET)
@ResponseBody
public Map<String, Object> beforeEdit(HttpServletRequest request,HttpSession session) {
Map<String, Object> resultMap = new HashMap<>();
String requestString = request.getParameter("saledata");//----may this change according to your json parsar
}
for php
$saledata = $this->getRequest()->getParam('saledata');
答案 1 :(得分:0)
正确答案来自Thilo。您只需添加&#34; saleData [OrderData] [0] [productId]&#34;作为参数名称而不是指定值。所以你可以这样:
final URIBuilder uriBuilder = new URIBuilder(apiUrl)
.setPath(this.apiStartPath)
.setParameter("saleData[OrderData][0][productId]", '12334')
......