php – 将此cURL转换为Guzzle

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 将此cURL转换为Guzzle脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我试过阅读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.1\n";
    $header .= "Host: domain.com\n";
    $header .= "Content-Length: ".strlen($xml)."\n";
    $header .= "Content-type: text/xml; charset=UTF8\n";
    $header .= "Connection: close; Keep-Alive\n\n";
    $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();;

脚本宝典总结

以上是脚本宝典为你收集整理的php – 将此cURL转换为Guzzle全部内容,希望文章能够帮你解决php – 将此cURL转换为Guzzle所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。