微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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();;

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐