如何在PHP cURL中设置端点?

时间:2016-03-08 13:54:56

标签: php curl

当我发送此请求时,我收到此错误:未找到操作的端点引用(EPR)是/ services / OrderWebService?wsdl =& tenant = virtual且WSA Action = null

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => "https://app.onebillsoftware.com/services/OrderWebServicewsdl
=&tenant=virtual",

CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "<soap:Envelopexmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\"  xmlns:ser=\"http://service.order.webservice.onebill.tarshan.com\"  xmlns:xsd=\"http://request.order.webservice.onebill.tarshan.com/xsd\">\r\n    <soap:Header/>\r\n   <soap:Body>\r\n      <ser:getOrder>\r\n         <!-- Optional:-->\r\n         <ser:getOrderRequest>\r\n            <!--Optional:-- >\r\n            <xsd:orderNumber>OR8126</xsd:orderNumber>\r\n          </ser:getOrderRequest>\r\n      </ser:getOrder>\r\n    </soap:Body>\r\n</soap:Envelope>",
 CURLOPT_HTTPHEADER => array(
 "authorization: Basic ZHNjb3R0QHZ0Z3VzLmNvbTpBa29vc3dhZzQxOQ==",
 "cache-control: no-cache",
 "postman-token: 2a90fa5f-a68c-39d2-dadb-bf39424a7535",
 "tenant: virtual"
 ),
 ));

$ response = curl_exec($ curl);    $ err = curl_error($ curl);

curl_close($卷曲);

 if ($err) {
 echo "cURL Error #:" . $err;
} else {
echo $response;

4 个答案:

答案 0 :(得分:1)

http://php.net/manual/en/curl.examples-basic.php

$ch = curl_init("http://www.example.com/");

这是一次谷歌搜索。

答案 1 :(得分:0)

有多种方式,我想到的两种方式如下:

初始化cURL句柄时可以设置URL,即

$curl = curl_init("https://www.example.com/");

或者您可以使用curl_setopt()常量来执行此操作,如下所示:

curl_setopt($curl, CURLOPT_URL, "https://www.example.com/");

可以在manual

中找到PHP cURL库的完整文档

答案 2 :(得分:0)

//function should be defined in your fn.core.php file
function getDataFromUrl($url){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}

//use function by requiring the file.
$response = getDataFromUrl("http://www.example.com/path/to/file.json");

//use response here
if($response){
  //process data
}else{
  //something goes wrong...
}

答案 3 :(得分:0)

$bodydata = array('user_id'=>$user_id,'api_token'=>$api_token,etc)
$endpoint = 'API URL';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 1000);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$bodydata);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
curl_close($ch);