繁体   English   中英

如何在bash中执行CURL post命令?

[英]How to execute CURL post command in bash?

我正在尝试通过bash脚本执行curl post命令,并且面临很多问题。

这是我的bash代码:

#!/bin/bash
url='http://slc760.us.oracle.com:10601/crmCommonApi/resources/latest'
Content='Content-Type:application/vnd.oracle.adf.batch+json'
user="sales_representative"
payload='{ "parts": [{"id": "part1","path": "/latest/__ORACO__Inventory_c","operation": "create","payload": {"__ORACO__Product_Id2_c":204,"__ORACO__Facing_c":"20","__ORACO__Product_Id1_c":204,"__ORACO__Product_c": "Ghirardelli White Choco","__ORACO__ShelfStock_c":"10","__ORACO__Location_c" : "Aisle 2","Organization_Id___ORACO__Account_Inventory":"300100051199355"}},{"id": "part1","path": "/latest/__ORACO__Inventory_c","operation": "create","payload": {"__ORACO__Product_Id2_c":204,"__ORACO__Facing_c":"3","__ORACO__Product_Id1_c":204,"__ORACO__Product_c": "Ghirardelli White Chocolcate","__ORACO__ShelfStock_c":"4","__ORACO__Location_c" : "Aisle 2","Organization_Id___ORACO__Account_Inventory":"300100051199355"}}]}'

curl -X POST -H "Content-Type:application/vnd.oracle.adf.batch+json" \
    --data $payload \
    $url \
    --user $user

运行时抛出错误:

curl: (6) Could not resolve host: "parts"
curl: (3) [globbing] bad range specification in column 2
curl: (6) Could not resolve host: "part1","path"
curl: (6) Could not resolve host: "
curl: (6) Could not resolve host: "create","payload"
curl: (3) [globbing] unmatched brace in column 1
curl: (6) Could not resolve host: "Ghirardelli
curl: (6) Could not resolve host: White
curl: (6) Could not resolve host: Choco","__ORACO__ShelfStock_c"
curl: (7) Failed to connect to  port 80: Connection refused
curl: (6) Could not resolve host: "Aisle
curl: (3) [globbing] unmatched close brace/bracket in column 66
curl: (6) Could not resolve host: "part1","path"
curl: (6) Could not resolve host: "
curl: (6) Could not resolve host: "create","payload"
curl: (3) [globbing] unmatched brace in column 1
curl: (6) Could not resolve host: "Ghirardelli
curl: (6) Could not resolve host: White
curl: (6) Could not resolve host: Chocolcate","__ORACO__ShelfStock_c"
curl: (7) Failed to connect to  port 80: Connection refused
curl: (6) Could not resolve host: "Aisle
curl: (3) [globbing] unmatched close brace/bracket in column 66
org.codehaus.jackson.JsonParseException: Unexpected end-of-input: expected close marker for OBJECT (from [Source: weblogic.servlet.internal.ServletInputStreamImpl@10514b51; line: 1, column: 0])

当通过命令行单独执行时,该命令似乎可以正常工作,但是当我尝试在CURL中执行该命令时,它会抛出上述错误。我知道相对于引号/语法,我丢失了。

请尝试更改以下行:

--data $payload

--data '$payload'

尝试在有效负载上加上双引号:

curl -X POST -H "Content-Type:application/vnd.oracle.adf.batch+json" \
--data "$payload" \
$url \
--user $user

那应该工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM