相同的 curl 命令不適用于 bash 腳本。任何人都可以
控制臺嘗試(成功一次):
curl -ki \
--cookie cookie-jar.txt \
--header 'Content-Type: text/xml' \
--request POST https://testserver:1234/v1/secondarylogin \
--data '<?xml version="1.0" encoding="UTF-8"?>
<p:secondaryloginrequest xmlns:p="http://www.ericsson.com/em/am/co/authentication/v1_0/">
<credential>
<secret>6673</secret>
<type>otp</type>
</credential>
<channelinformation>COMVIVAAGENTAPP</channelinformation>
</p:secondaryloginrequest>'
**HTTP/1.1 200 OK**
Date: Wed, 02 Mar 2022 10:52:01 GMT
Content-Type: text/xml;charset=utf-8
Date: Wed, 02 Mar 2022 10:52:02 GMT
Set-Cookie: sessionid=default0c07b834d30644e9b30a9bfced82e6f2
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Content-Length: 0
一個非常簡單的 Bash 腳本(失敗了):
sh sectest.sh 6673
#!/usr/bin/bash
curl -ki \
--cookie cookie-jar.txt \
--header 'Content-Type: text/xml' \
--request POST https://ugtestpo:8446/v1/secondarylogin \
--data '<?xml version="1.0" encoding="UTF-8"?>
<p:secondaryloginrequest xmlns:p="http://www.ericsson.com/em/am/co/authentication/v1_0/">
<credential>
<secret>"$1"</secret>
<type>otp</type>
</credential>
<channelinformation>COMVIVAAGENTAPP</channelinformation>
</p:secondaryloginrequest>'
HTTP/1.1 401 Unauthorized
Date: Wed, 02 Mar 2022 10:47:53 GMT
Content-Type: text/xml;charset=utf-8
Content-Length: 188
我不能以引數方式傳遞我的秘密值。
uj5u.com熱心網友回復:
將我的評論轉換為答案,以便將來的訪問者輕松找到該解決方案。
以下應該對您有用,并且允許$1擴展的正確參考:
curl -ki \
--cookie cookie-jar.txt \
--header 'Content-Type: text/xml' \
--request POST https://ugtestpo:8446/v1/secondarylogin \
--data '<?xml version="1.0" encoding="UTF-8"?>
<p:secondaryloginrequest xmlns:p="http://www.ericsson.com/em/am/co/authentication/v1_0/">
<credential>
<secret>'"$1"'</secret>
<type>otp</type>
</credential>
<channelinformation>COMVIVAAGENTAPP</channelinformation>
</p:secondaryloginrequest>'
uj5u.com熱心網友回復:
為了可讀性,我將 xml 分配給一個變數: heredocs 有助于避免參考地獄。
#!/usr/bin/bash
payload=$(cat <<END_XML
<?xml version="1.0" encoding="UTF-8"?>
<p:secondaryloginrequest xmlns:p="http://www.ericsson.com/em/am/co/authentication/v1_0/">
<credential>
<secret>$1</secret>
<type>otp</type>
</credential>
<channelinformation>COMVIVAAGENTAPP</channelinformation>
</p:secondaryloginrequest>
END_XML
)
curl -ki \
--cookie cookie-jar.txt \
--header 'Content-Type: text/xml' \
--request POST \
--data "$payload" \
https://ugtestpo:8446/v1/secondarylogin
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/443513.html
