JSDogwood
asked on
curl request processing twice?
I am using curl to post to a remote soap server. It works, connects, passes the correct data to the system as i would expect, but for some reason curl is running twice. I have verified that my code is not running twice to trigger it. A single call to curl causes 2 sets of data to go to the soap server. In this case, I am simply adding lead to a lead management system and end up with duplicate leads.
I have read a number of similar questions on other forums and sites, but have not seen a solution.
The remote server is an https connection, but does not require authentication.
Could there be something on the other end causing this?
I have used the exact same code/curl options to connect to many other servers without a problem. So i just wanted to see if any of the experts here had ever encountered this or had any suggestions.
Thanks,
John
I have read a number of similar questions on other forums and sites, but have not seen a solution.
The remote server is an https connection, but does not require authentication.
Could there be something on the other end causing this?
I have used the exact same code/curl options to connect to many other servers without a problem. So i just wanted to see if any of the experts here had ever encountered this or had any suggestions.
Thanks,
John
Please provide the code which call these curl function.
ASKER
Here is some base code with the function that calls curl
<?PHP
function newLead() {
$soap_request = "<?xml version=\"1.0\"?>\n";
$soap_request .= "<soapenv:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:SyncLeadWS\">\n";
$soap_request .= " <soapenv:Header/>\n";
$soap_request .= " <soapenv:Body>\n";
$soap_request .= " <urn:addNewLead soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n";
$soap_request .= " <ArrayOfLeadInfo xsi:type=\"urn:ArrayOfLeadInfo\">\n";
$soap_request .= " <leadDetails xsi:type=\"urn:LeadInfo\">\n";
$soap_request .= " <city xsi:type=\"xsd:string\">" . $_POST[City] ."</city>\n";
$soap_request .= " <emailID xsi:type=\"xsd:string\">" . $_POST[email] ."</emailID>\n";
$soap_request .= " <firstName xsi:type=\"xsd:string\">" . $_POST[fName] ."</firstName>\n";
$soap_request .= " <howDidYouHereAboutUs xsi:type=\"xsd:string\">" . $_POST[lead_source] ."</howDidYouHereAboutUs>\n";
$soap_request .= " <howDidYouHereAboutUsDetails xsi:type=\"xsd:string\">" . $_POST[lead_source2] ."</howDidYouHereAboutUsDetails>\n";
$soap_request .= " <lastName xsi:type=\"xsd:string\">" . $_POST[lName] ."</lastName>\n";
$soap_request .= " <phone xsi:type=\"xsd:string\">" . $_POST[phone] ."</phone>\n";
$soap_request .= " <state xsi:type=\"xsd:string\">" . $_POST[State] ."</state>\n";
$soap_request .= " </leadDetails>\n";
$soap_request .= " </ArrayOfLeadInfo>\n";
$soap_request .= " <syncKey xsi:type=\"xsd:string\">$authkey</syncKey>\n";
$soap_request .= " </urn:addNewLead>\n";
$soap_request .= " </soapenv:Body>\n";
$soap_request .= "</soapenv:Envelope>";
$header = array(
"Content-type: text/xml;charset=\"utf-8\"",
"SOAPAction: addNewLead",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"Content-length: ".strlen($soap_request),
);
$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL, 'https://www.pathtowsdlgoeshere.com?wsdl' );
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10000);
curl_setopt($soap_do, CURLOPT_TIMEOUT, 10000);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_FOLLOWLOCATION, 0); #added this in to test but had no effect
curl_setopt($soap_do, CURLOPT_VERBOSE, 1); #added this in to test but had no effect
curl_setopt($soap_do, CURLOPT_FORBID_REUSE, true); #added this in to test but had no effect
curl_setopt($soap_do, CURLOPT_FRESH_CONNECT, 1); #added this in to test but had no effect
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soap_do, CURLOPT_POST, true );
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $soap_request);
curl_setopt($soap_do, CURLOPT_HTTPHEADER, array('Expect:')); #added this in to test but had no effect
curl_setopt($soap_do, CURLOPT_HTTPHEADER, $header);
$result = curl_exec($soap_do);
if(curl_exec($soap_do) === false) {
$err = 'Curl error: ' . curl_error($soap_do);
curl_close($soap_do);
print $err;
} else {
curl_close($soap_do);
print 'Operation completed without any errors';
}
try {
$response_string = $result;
$response_string = str_replace( '<soapenv:', '<s_', $response_string);
$response_string = str_replace('</soapenv:', '</s_', $response_string);
$response_string = str_replace( '<xs:', '<xs_', $response_string);
$response_string = str_replace( '</xs:', '</xs_', $response_string);
$response_string = str_replace( '<diffgr:', '<d_', $response_string);
$response_string = str_replace( '</diffgr:', '</d_', $response_string);
$xml_leads = simplexml_load_string($response_string);
if ($xml_leads->s_Body->multiRef->leadID) {
foreach ($xml_leads->s_Body->multiRef as $SpecialResultItem)
{
$leadID = $SpecialResultItem->leadID;
$returnType = $SpecialResultItem->returnType;
print "$leadID: $returnType ";
}
#END addLead loop
} #end if lead made it
else { print "Oops, there was an error processing your request."; }
} catch (SOAPFault $exception) {
// if we hit an error, print the exception and the XML we sent
print $exception;
print htmlspecialchars($client->__getLastRequest());
exit;
}
} #end function
?>
<?PHP
if ($_POST[fName] AND $_POST[lName] AND $_POST[State] AND $_POST[email] AND $_POST[lead_source] AND $_POST[lead_source2]) {
newLead();
}
?>
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
@Kravimir: +1 !
Glad you're at EE,
~Ray
Glad you're at EE,
~Ray
ASKER
Thanks Kravmir. Not sure how I glossed over that, but that indeed was the issue and solved the issue.