我正在尝试通过 PHP 中的 Curl 发送 SOAP 帖子,但我总是遇到无法连接到主机的问题。但是当我尝试在基于 web 的客户端(如 hurl)中使用相同的 URL 时,得到了正确的响应:
- 投掷测试:http ://www.hurl.it
我的代码:
$url = "https://gateway.monster.com/bgwBroker"; $soapMessage = '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">' . '<SOAP-ENV:Header>'. '<mh:MonsterHeader xmlns:mh="http://schemas.monster.com/MonsterHeader">'. '<mh:MessageData>'. '<mh:MessageId>PresenceMedia SARL Jobs</mh:MessageId>'. '<mh:Timestamp>2004-06-09T14:41:44Z</mh:Timestamp>'. '</mh:MessageData>'. '</mh:MonsterHeader>'. '<wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/04/secext">'. '<wsse:UsernameToken>'. '<wsse:Username>xrtpjobsx01</wsse:Username>'. '<wsse:Password>rtp987654</wsse:Password>'. '</wsse:UsernameToken>'. '</wsse:Security>'. '</SOAP-ENV:Header>'. '<SOAP-ENV:Body>'. '<Job jobRefCode="Job - minimal fields" jobAction="addOrUpdate" jobComplete="true" xmlns="http://schemas.monster.com/Monster" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schemas.monster.com/Monster http://schemas.monster.com/Current/xsd/Monster.xsd">'. '<RecruiterReference>'. '<UserName>xrtpjobsx01</UserName>'. '</RecruiterReference>'. '<JobInformation>'. '<JobTitle><![CDATA[PresenceMedia SARL its a simple test from morocco blablablablablablablablablablablabla]]></JobTitle>'. '<JobStatus monsterId="4">JobTypeFullTime</JobStatus>'. '<PhysicalAddress>'. '<City>Rabat Shore</City>'. '<State>NY</State>'. '<CountryCode>US</CountryCode>'. '<PostalCode>11220</PostalCode>'. '</PhysicalAddress>'. '<JobBody><![CDATA[PresenceMedia SARL Body blablabla blablabla blablabla blablabla blablabla blablabla blablabla]]></JobBody>'. '</JobInformation>'. '<JobPostings>'. '<JobPosting>'. '<Location>'. '<City>London East</City>'. '<State>London</State>'. '<CountryCode>UK</CountryCode>'. '</Location>'. '<JobCategory monsterId="47" />'. '<JobOccupations>'. '<JobOccupation monsterId="11909" />'. '</JobOccupations>'. '<BoardName monsterId="1" />'. '<Industries>'. '<Industry>'. '<IndustryName monsterId="1" />'. '</Industry>'. '</Industries>'. '</JobPosting>'. '</JobPostings>'. '</Job>'. '</SOAP-ENV:Body>'. '</SOAP-ENV:Envelope>'; $headers = array( "Content-type: text/xml;charset=\"utf-8\"", "Accept: text/xml", "Cache-Control: no-cache", "Pragma: no-cache", "SOAPAction: \"run\"", "Content-length: ".strlen($soapMessage), ); $soapUser = "xrtpjobsx01"; $soapPassword = "rtp987654"; $soap_do = curl_init(); curl_setopt($soap_do, CURLOPT_URL, $url); curl_setopt($soap_do, CURLOPT_PORT, 8443); curl_setopt($soap_do, CURLOPT_USERPWD, $soapUser.":".$soapPassword); curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true ); 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_TIMEOUT,9000); curl_setopt($soap_do, CURLOPT_POSTFIELDS, $soapMessage); curl_setopt($soap_do, CURLOPT_HTTPHEADER, $headers); $result = curl_exec($soap_do); $err = curl_error($soap_do); echo "Result:" . $result; echo "<br>Error:" . $err ; echo "<b><pre>"; var_dump(curl_getinfo($soap_do)); echo "</pre>"; ?>