I am attempting to call a SOAP API and then load some XML information from user input.
I have a from with POST value data. However, I am unable to get around a 401 Error. I am authorized but I feel as if I am not correctly passing the data. However, I am having trouble with finding the answer.
This is what is going on with my data exchange:
Server Side:
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;
}
}
Client Side:
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.");
}
});
});
});
What is dynamic in the form:
<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']; ?>" >
The XML Loads but with this error:
401 Authorization Required
nginx