加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 将此cURL转换为Guzzle

发布时间:2020-12-13 13:29:24 所属栏目:PHP教程 来源:网络整理
导读:我试过阅读Guzzle文档,但我无法解决这个问题. 我想使用Guzzle代替cURL以下内容: protected $url = 'https://secure.abcdef.com/cgi/xml_request_server.php'; $xml = "ABCRequestn"; $xml .= "Authenticationn"; $xml .= "ABLogin$this-gwlogin/ABLoginn
我试过阅读Guzzle文档,但我无法解决这个问题.

我想使用Guzzle代替cURL以下内容:

protected $url = 'https://secure.abcdef.com/cgi/xml_request_server.php';

    $xml =  "<ABCRequest>n";
    $xml .=     "<Authentication>n";
    $xml .=         "<ABLogin>$this->gwlogin</ABLogin>n";
    $xml .=         "<ABKey>$this->gwkey</ABKey>n";
    $xml .=     "</Authentication>n";
    $xml .=     "<Request>n";
    $xml .=            "<RequestType>SearchABC</RequestType>n";
    $xml .=        "</Request>n";
    $xml .= "</ABCRequest>n";

    $header =  "POST $this->url HTTP/1.1n";
    $header .= "Host: domain.comn";
    $header .= "Content-Length: ".strlen($xml)."n";
    $header .= "Content-Type: text/xml; charset=UTF8n";
    $header .= "Connection: close; Keep-Alivenn";
    $header .= $xml;

    $ch = curl_init();

    curl_setopt($ch,CURLOPT_URL,$this->url);
    curl_setopt($ch,CURLOPT_TIMEOUT,120);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch,CURLOPT_CUSTOMREQUEST,$header);

    $response = curl_exec($ch);
    curl_close($ch);

我试过这个,但我还是新来的…:

$client = new Client($this->url);
$response = $client->get($xml);
您可以使用 Client::post()创建HTTP POST请求:
$client = new Client($this->url);
$request = $client->post(
    '',['Content-Type' => 'text/xml; charset=UTF8'],$xml,['timeout' => 120]
);
$response = $request->send()->xml();;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读