gpt4 book ai didi

php - 如何在 PHP 中禁用 Curl 调试输出

转载 作者:可可西里 更新时间:2023-11-01 16:50:56 26 4
gpt4 key购买 nike

我写了一个 PHP CUrl 类,如果我执行应该返回内容的方法,它首先返回标题,然后返回内容。所以我无法解析任何 XML 数据。我需要禁用此示例输出。

HTTP/1.1 200 OK
Date: Thu, 01 Apr 2010 20:11:58 GMT
Server: Apache/2.2.9 (Debian) PHP/5.2.6-1+lenny4 with Suhosin-Patch mod_ssl/2.2.9 OpenSSL/0.9.8g
X-Powered-By: PHP/5.2.6-1+lenny4
Set-Cookie: PHPSESSID=44beccf62f87546140d4a0bd24bd28b0; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Transfer-Encoding: chunked
Content-Type: application/xml

这是 Curl 类

<?php

class Test_Curl
{
protected $curl;
protected $headers;
protected $useragent;
protected $url;
protected $testkey;

public function __construct()
{

}

public function setUseraget($useragent)
{
$this->useragent = $useragent;
return $this;
}

public function setApiKey($key)
{

$this->billomatApiKey = $key;
}

private function curlExecGeneral()
{
$result = curl_exec($this->curl);
curl_close($this->curl);
return $result;
}



private function curlInitGeneral($request)
{
$this->curl = curl_init($request);
curl_setopt($this->curl, CURLOPT_HEADER, true);
curl_setopt($this->curl, CURLOPT_HTTPHEADER, array("X-testkey: ".$this->testkey, "Content-Type: application/xml"));
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
}

public function get($request)
{
$this->curlInitGeneral($request);
curl_setopt ($this->curl, CURLOPT_HTTPGET, true);
return $this->curlExecGeneral();
}

public function post($request, $xml)
{
$this->curlInitGeneral($request);
curl_setopt ($this->curl, CURLOPT_POST, true); //set the Requestmethod to POST
curl_setopt ($this->curl, CURLOPT_POSTFIELDS, $xml); //add the xml data to the Request
return $this->curlExecGeneral();
}



}
?>

最佳答案

参见 cURL options :

curl_setopt($ch, CURLOPT_HEADER, 0);

关于php - 如何在 PHP 中禁用 Curl 调试输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2563393/

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