您无需传递引号将自定义标头括起来即可卷曲。另外,
data应在参数中间加上变量。
首先,编写一个函数来生成脚本的发布数据。这使您免于有关shell引用的种种麻烦,并且使读取维护脚本比在curl调用行中输入post数据更容易,如您的尝试:
generate_post_data(){ cat <<EOF{ "account": { "email": "$email", "screenName": "$screenName", "type": "$theType", "passwordSettings": { "password": "$password", "password/confirm/i": "$password" } }, "firstName": "$firstName", "lastName": "$lastName", "middleName": "$middleName", "locale": "$locale", "registrationSiteId": "$registrationSiteId", "receiveEmail": "$receiveEmail", "dateOfBirth": "$dob", "mobileNumber": "$mobileNumber", "gender": "$gender", "fuelActivationDate": "$fuelActivationDate", "postalCode": "$postalCode", "country": "$country", "city": "$city", "state": "$state", "bio": "$bio", "jpFirstNameKana": "$jpFirstNameKana", "jpLastNameKana": "$jpLastNameKana", "height": "$height", "weight": "$weight", "distanceUnit": "MILES", "weightUnit": "POUNDS", "heightUnit": "FT/INCHES"}EOF}然后很容易在curl的调用中使用该函数:
curl -i -H "Accept: application/json" -H "Content-Type:application/json" -X POST --data "$(generate_post_data)" "https://xxx:xxxxx@xxxx-www.xxxxx.com/xxxxx/xxxx/xxxx"
就是说,这里有一些关于shell引用规则的说明:
-H参数中的双引号(如所示
-H "foo bar")告诉bash将内部内容作为单个参数保留(即使它包含空格)。
--data参数中的单引号(如中的
--data 'foo bar')执行相同的操作,只是它们逐字传递所有文本(包括双引号和美元符号)。
要在单引号引起的文本中间插入变量,您必须结束单引号,然后将其与双引号变量连接,然后重新打开单引号以继续文本:
'foobar'"$variable"'more foo'。



