我要使用curl
my $workItemCommentorURL = "://xyz.com/jazz/oslc/users.json?oslc_cm.query=rtc_cm:userId="$id"&oslc_cm.properties=dc:title"
我收到错误:
Scalar found where operator expected at ./clone.pl line 90, near ""://xyz.com/jazz/oslc/users.json?oslc_cm.query=rtc_cm:userId="$id"
(Missing operator before $id?)
String found where operator expected at ./clone.pl line 90, near "$id"&oslc_cm.properties=dc:title""
尝试使用以下选项转义双引号:
"://xyz.com/jazz/oslc/users.json?oslc_cm.query=rtc_cm:userId=\"&id\"&oslc_cm.properties=dc:title"
"https://xyz.com/jazz/oslc/users.json?oslc_cm.query=rtc_cm:\"userId=" .$id. "\"&oslc_cm.properties=dc:title"
这样可以得到结果,但仍然收到警告信息:
sh: oslc_cm.properties=dc:title: command not found
如何在URL中转义引号以获得结果而不发出警告sh: oslc_cm.properties=dc:title: command not found
我的代码是:
my $workItemCommentorURL = "https://xyz.com/jazz/oslc/users.json?oslc_cm.query=rtc_cm:userId=\"$id\"&oslc_cm.
my $result = qx(curl -s -D - -k -b ~/.jazzcookies -o commentor.json -H \"Accept: application/x-oslc-cm-changerequest+json\" $workItemCommentorURL);
答案 0 :(得分:3)
您从sh
收到的邮件是由网址中的&
引起的。需要为shell转义/引用url。否则,shell会将&
解释为特殊字符。
试试这个(注意单引号):
my $result = qx(curl -s -D - -k -b ~/.jazzcookies -o commentor.json -H 'Accept: application/x-oslc-cm-changerequest+json' '$workItemCommentorURL');
答案 1 :(得分:2)
如果您不想插入变量。使用单引号:
my $workItemCommentorURL = '://xyz.com/jazz/oslc/users.json?oslc_cm.query=rtc_cm:userId="$id"&oslc_cm.properties=dc:title';
如果您确实需要插值,请使用替代形式qq{}
:
my $workItemCommentorURL = qq{://xyz.com/jazz/oslc/users.json?oslc_cm.query=rtc_cm:userId="$id"&oslc_cm.properties=dc:title};