gpt4 book ai didi

未设置 PHP cURL 选项

转载 作者:行者123 更新时间:2023-12-04 19:37:26 25 4
gpt4 key购买 nike

我有一个调用本地 tomcat REST 服务器的 php REST 客户端,并且过去几年一直在生产服务器上使用它。

我不得不进行一些不相关的客户端 CSS 更改,并且必须构建我的开发环境来测试它们是否正常,然后再推送到 prod。由于我安装的 vagrant 版本发生了一些变化,我不得不更改它使用的 vagrant box,我认为这是导致所有问题的原因。

当我发出 cURL 请求时,似乎发生了一些奇怪的事情,并且没有正确创建请求。

这是我的客户端代码(目前正在生产中):

class RestClient {

private $baseEndpoint;
private $username;
private $password;
private $siteCode;

function __construct($baseEndpoint, $username, $password, $siteCode) {
$this -> baseEndpoint = $baseEndpoint;
$this -> username = $username;
$this -> password = $password;
$this -> siteCode = $siteCode;
}

public function get($endpoint) {
//die($this -> baseEndpoint . $endpoint); //comment1
$curlResource = curl_init($this -> baseEndpoint . $endpoint);
curl_setopt_array($curlResource, array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTPHEADER => array(
"Accept:application/json",
"Content-Type:application/json",
"Site-Code:" . $this -> siteCode,
),
CURLOPT_USERPWD => $this -> username . ":" . $this -> password
));

$curlResponse = curl_exec($curlResource);
// echo curl_error($curlResource); //comment2
$resultStatus = curl_getinfo($curlResource);
// print_r($resultStatus); die(); //comment3

$statusCode = $resultStatus['http_code'];

if($statusCode != 200) {
throw new Exception("500");
}

$restResponse = new Response();
$restResponse -> setStatus($statusCode);
$restResponse -> setEntity($curlResponse);

return $restResponse;
}
  • 如果我取消注释comment1,我会得到我所期望的-“http://localhost:8080/webApp/endpoint
  • 如果我取消注释comment2,我会得到“无法连接到::1:权限被拒绝”,这根本不正确......我在谷歌上搜索了这个错误,它们似乎都显示了请求端点。
  • 如果我取消注释comment3,我会得到“数组([url] => http://localhost:8080/webApp/endpoint [content_type] => [http_code] => 0 [header_size] => 0 [request_size] => 0 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0 [namelookup_time] => 0.000515 [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 [redirect_url] => [primary_ip] => 127.0.0.1 [certinfo] = > Array ( ) )”,这似乎表明我没有设置任何选项。

  • 一些笔记:
  • 当我运行 curl 请求(curl --user user:password --header "site-code: london"http://localhost:8080/webApp/endpoint )时,我得到了正确的响应。
  • 开发环境php版本为5.6.27,生产环境为5.6.26。
  • 操作系统版本均为 CentOS release 6.8
  • php cURL 信息如下:
  • cURL support enabled
    cURL Information 7.19.7
    Age 3
    Features
    AsynchDNS No
    CharConv No
    Debug No
    GSS-Negotiate Yes
    IDN Yes
    IPv6 Yes
    krb4 No
    Largefile Yes
    libz Yes
    NTLM Yes
    SPNEGO No
    SSL Yes
    SSPI No
    Protocols tftp, ftp, telnet, dict, ldap, ldaps, http, file, https, ftps, scp, sftp
    Host x86_64-redhat-linux-gnu
    SSL Version NSS/3.21 Basic ECC
    ZLib Version 1.2.3
    libSSH Version libssh2/1.4.2

    最佳答案

    关于未设置 PHP cURL 选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40576179/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com