我试图在PHP中发出SOAP请求.我有我的服务URL,当我在SOAP UI中检查它时,我可以看到以下内容
所以我想用它来登录.目前,我正在尝试以下内容
public function updateApi(){ $service_url = 'https://someurl.com/sdk/user/session/logon'; $curl = curl_init($service_url); $curl_post_data = array( "ApiKey" => 'somekey', "ApiSecret" => 'somesecret', ); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data); $curl_response = curl_exec($curl); curl_close($curl); var_dump($curl_response); }
但是,我总是收到登录失败的错误响应.我是否必须调用登录方法或其他什么?真的只是寻找一些关于我是否正确做事的建议.
谢谢
您没有设置Content-Type
标题告诉您发布的内容的格式:
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/x-www-form-urlencoded'));
否则,从php5以上,http_build_query
建议使用:
$curl_post_data = array( "ApiKey" => 'somekey', "ApiSecret" => 'somesecret', ); curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($curl_post_data));
希望它对你有帮助,蒂埃里
根据XML,您应该尝试将curl_post_data变量作为URL编码字符串发送.喜欢urlencode('ApiKey=somekey&ApiSecret=somesecret')
,其次尝试将您的请求的内容类型设置为' application/x-www-form-urlencoded
'
$service_url = 'https://someurl.com/sdk/user/session/logon'; $curl = curl_init($service_url); $headers = ["Content-Type: application/json"]; // or other supported media type $curl_post_data = array( "ApiKey" => 'somekey', "ApiSecret" => 'somesecret', ); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data); curl_setopt($rest, CURLOPT_HTTPHEADER,$headers); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $curl_response = curl_exec($curl); curl_close($curl);