cURL 在 PHP 中不起作用?
cURL not working in PHP?
我有以下 php 功能:
function checkJQL($filter) {
$auth = "account:password";
$URL='http://jira/rest/api/latest/search?jql='.$filter;
echo $URL;
// Initiate curl
$ch = curl_init();
// Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//Tell it to always go to the link
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the url
curl_setopt($ch, CURLOPT_URL,$URL);
//Set username and password
curl_setopt($ch, CURLOPT_USERPWD, $auth);
// Execute
$result=curl_exec($ch);
// Closing
curl_close($ch);
echo $result;
// Will dump a beauty json :3
var_dump(json_decode($result, true));
echo "DONE";
}
当我用 $filter = ""
调用它时它工作正常,输出所有内容。一旦我插入正确的 JQL 查询,它就会失败。当我输入随机垃圾时,它可以工作(就像我收到无效的输入消息一样),但是当它是正确的 JQL 时,它永远不会工作。
当我将回显的 URL 复制并粘贴到浏览器中时,它起作用了。
我使用的示例过滤器:
"Target" = "Blah"
当我想到它时,我实际上并不需要它工作,我只需要它知道何时输入不是 JQL(它确实如此)。但我现在真的很好奇。有人知道它可能是什么吗?
您应该 URL-编码 $filter
。
之所以它适用于空字符串或随机字符串,是因为它们没有任何需要 URL 编码的具有挑战性的字符。
URL 在浏览器中有效但在脚本中无效的原因是浏览器进行了 URL 编码。
所以请执行以下操作:
$URL='http://jira/rest/api/latest/search?jql='.urlencode($filter);
Link 到 urlencode:http://php.net/manual/en/function.urlencode.php
我有以下 php 功能:
function checkJQL($filter) {
$auth = "account:password";
$URL='http://jira/rest/api/latest/search?jql='.$filter;
echo $URL;
// Initiate curl
$ch = curl_init();
// Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//Tell it to always go to the link
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the url
curl_setopt($ch, CURLOPT_URL,$URL);
//Set username and password
curl_setopt($ch, CURLOPT_USERPWD, $auth);
// Execute
$result=curl_exec($ch);
// Closing
curl_close($ch);
echo $result;
// Will dump a beauty json :3
var_dump(json_decode($result, true));
echo "DONE";
}
当我用 $filter = ""
调用它时它工作正常,输出所有内容。一旦我插入正确的 JQL 查询,它就会失败。当我输入随机垃圾时,它可以工作(就像我收到无效的输入消息一样),但是当它是正确的 JQL 时,它永远不会工作。
当我将回显的 URL 复制并粘贴到浏览器中时,它起作用了。 我使用的示例过滤器:
"Target" = "Blah"
当我想到它时,我实际上并不需要它工作,我只需要它知道何时输入不是 JQL(它确实如此)。但我现在真的很好奇。有人知道它可能是什么吗?
您应该 URL-编码 $filter
。
之所以它适用于空字符串或随机字符串,是因为它们没有任何需要 URL 编码的具有挑战性的字符。
URL 在浏览器中有效但在脚本中无效的原因是浏览器进行了 URL 编码。
所以请执行以下操作:
$URL='http://jira/rest/api/latest/search?jql='.urlencode($filter);
Link 到 urlencode:http://php.net/manual/en/function.urlencode.php