【问题标题】:why is this curl function getting permission denied为什么这个 curl 函数获得权限被拒绝
【发布时间】:2020-01-03 16:52:28
【问题描述】:

我正在尝试与 Kodi JSONRPC api 进行通信,但我一直收到被拒绝的权限。

我到处寻找,我尝试了所有我能找到的 curl 选项,但似乎都没有做任何事情。

$options = array(
        CURLOPT_VERBOSE => 1,
        CURLOPT_RETURNTRANSFER      => true,
        CURLOPT_HEADER              => true,
        CURLOPT_HTTPHEADER          => array(                                                                          
        'Content-Type: application/json',                                                                                
        'Content-Length: ' . strlen($data_string)),
        CURLOPT_ENCODING            => "",       
        CURLOPT_USERAGENT           => "curl/7.65.1", 
        CURLOPT_POSTFIELDS          => $data_string,
    );

$ch = curl_init( $url );
curl_setopt_array( $ch, $options );
$info = curl_getinfo($ch);
$content = curl_exec( $ch );

print_r($info);
echo $content;

我得到了一些令人不安的响应,我的 curl 请求如下所示:

Array
(
    [url] => http://10.1.1.214:8080/jsonrpc
    [content_type] => 
    [http_code] => 0
    [header_size] => 0
    [request_size] => 0
    [filetime] => 0
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 0
    [namelookup_time] => 0
    [connect_time] => 0
    [pretransfer_time] => 0
    [size_upload] => 0
    [size_download] => 0
    [speed_download] => 0
    [speed_upload] => 0
    [download_content_length] => -1
    [upload_content_length] => -1
    [starttransfer_time] => 0
    [redirect_time] => 0
    [certinfo] => Array
        (
        )

    [primary_ip] => 
    [primary_port] => 0
    [local_ip] => 
    [local_port] => 0
    [redirect_url] => 
)

我的 error_log 如下所示:

* About to connect() to 10.1.1.214 port 8080 (#69)
*   Trying 10.1.1.214...
* Failed to connect to 10.1.1.214: Permission denied
* couldn't connect to host at 10.1.1.214:8080
* Closing connection 69

来自命令行的成功命令如下所示:

curl -v --data-binary '{"jsonrpc": "2.0", "method": "Application.GetProperties", "params": {"properties": ["version"]}, "id": 1}' -H 'content-type: application/json'  http://10.1.1.214:8080/jsonrpc
*   Trying 10.1.1.214:8080...
* TCP_NODELAY set
* Connected to 10.1.1.214 (10.1.1.214) port 8080 (#0)
> POST /jsonrpc HTTP/1.1
> Host: 10.1.1.214:8080
> User-Agent: curl/7.65.1
> Accept: */*
> content-type: application/json
> Content-Length: 105
>
* upload completely sent off: 105 out of 105 bytes
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Connection: Keep-Alive
< Content-Length: 116
< Content-Type: application/json
< Cache-Control: private, max-age=0, no-cache
< Accept-Ranges: none
< Date: Fri, 30 Aug 2019 02:02:17 GMT
<
* Connection #0 to host 10.1.1.214 left intact
{"id":1,"jsonrpc":"2.0","result":{"version":{"major":18,"minor":3,"revision":"newclock5_18.3-Leia","tag":"stable"}}}

【问题讨论】:

  • 可能是防火墙问题!
  • 实际上,它是!......在我发现它是 SELINUX 策略后仅几个小时,很快就回答了这个问题。

标签: php json curl kodi


【解决方案1】:

事实证明,问题在于 SELINUX 策略。

通过运行以下命令,它将解决问题

#setsebool -P httpd_can_network_connect=1

【讨论】:

    猜你喜欢
    • 2011-03-29
    • 2014-10-09
    • 2021-01-21
    • 1970-01-01
    • 1970-01-01
    • 2018-04-06
    • 2014-05-29
    • 1970-01-01
    • 2011-03-29
    相关资源
    最近更新 更多