401错误,XML数据请求

时间:2018-03-07 14:02:56

标签: php curl soap basic-authentication php-curl

我试图调用SOAP API,然后从用户输入加载一些XML信息。

我有一个来自POST值的数据。但是,我无法解决401错误。我被授权但我觉得好像我没有正确传递数据。但是,我找不到答案。

这是我的数据交换所发生的事情:

服务器端:

function ddn_clientside()
{
    $curl = curl_init();

    curl_setopt_array($curl, array(
        CURLOPT_URL => "http://api.xxxxxxxxxxx.com/general/xxx/?wsdl=",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => "",
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => "GET",
        CURLOPT_HTTPHEADER => array(
            "Cache-Control: no-cache",
            "Postman-Token: xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx",
            "content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YRxkTrFu0gW"
        ),
    ));

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

    curl_close($curl);

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

客户端:

jQuery(function($) {
  $("#search_form").submit(function(event) {
    event.preventDefault();
    $.ajax({
      method: "POST",
      url: ddn_clientside.url,
      data: {
        action: "ddn_clientside",
        zip_code: $("#zip_code").val(),
        distance: $("#distance").val()
      },
      success: function(data) {
        alert(data);
      },
      fail: function(error) {
        alert("There was an error communicating with the server.");
      }
    });
  });
});

表格中的动态是什么:

<input type="text" id="zip_code" class="searchZip" placeholder="Please enter your zip code..." value="<?php $name = $_POST['zip_code']; ?>" maxlength="5" name="<?php $zip = $_POST['zip_code']; ?>">
<select name="distance" id="distance" value="<?php $name = $_POST['distance']; ?>" >

XML加载但出现此错误:    

401需要授权

    nginx的

0 个答案:

没有答案