您好我正在尝试通过CURL发送POST请求,但是它抛出了一个错误,表示为 “连接到qaservices.carrental.com:443失败;没有错误”。
用户名和密码已包含在xml文件的soap标头中
<?php
$filename = 'c:/v.xml';
$data = file_get_contents($filename);
$url = 'https://qaservices.carrental.com/wsbang/HTTPSOAPRouter/ws9071';
$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL, $url );
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_TIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_POST, true );
curl_setopt($soap_do, CURLOPT_HEADER, 0 );
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($soap_do);
$err = curl_error($soap_do);
if ( curl_errno($soap_do) )
{
$result = 'ERROR -> ' . curl_errno($soap_do) . ': ' . curl_error($soap_do);
}
else
{
$returnCode = (int)curl_getinfo($soap_do, CURLINFO_HTTP_CODE);
switch($returnCode)
{
case 200:
break;
default:
$result = 'HTTP ERROR -> ' . $returnCode;
break;
}
}
curl_close($ch);
echo $result;
?>
当我尝试在vb.net中发送HttpWebRequest时,这有效。 vb.net中的代码副本是
doc.Load("c:/v.xml")
Dim content As String = doc.InnerXml
Dim urlEncoded As String = content
Dim encodedRequest As Byte() = New ASCIIEncoding().GetBytes(urlEncoded)
Dim request As HttpWebRequest = DirectCast(WebRequest.Create("https://qaservices.carrental.com/wsbang/HTTPSOAPRouter/ws9071"), HttpWebRequest)
request.Method = "POST"
request.Accept = "*/*"
request.ContentType = "application/x-www-form-urlencoded"
' request.UserAgent = "Custom REST client v1.0"
request.ContentLength = encodedRequest.Length
request.Proxy.Credentials = CredentialCache.DefaultCredentials
Dim reqStream As Stream = request.GetRequestStream()
reqStream.Write(encodedRequest, 0, encodedRequest.Length)
reqStream.Flush()
reqStream.Close()
Dim response As HttpWebResponse = (request.GetResponse())
Dim responseStream As Stream = response.GetResponseStream()
Dim streamReader As New StreamReader(responseStream)
Dim responseContent As String = streamReader.ReadToEnd
我认为它必须在设置代理凭据方面做点什么。任何人都可以指导我走正确的路径
答案 0 :(得分:0)
两个SSL证书在主机和节点上都有效吗?如果没有,则添加以下选项。这将绕过SSL验证并让您连接
curl_setopt ($soap_do, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($soap_do, CURLOPT_SSL_VERIFYPEER, 0);
答案 1 :(得分:0)
来自curl / php的互联网连接请求被Windows服务器拒绝了。如果你的电脑连接到Windows网络,一些非微软应用程序,如fiddler,esclipse,maven将无法连接到互联网。您需要安装cntlm代理,它将为您请求添加标头,以便它可以连接到Internet。 我已经配置cntlm来查看端口3127
在上面的代码中我添加了 $ proxy ='127.0.0.1:3127'; curl_setopt($ soap_do,CURLOPT_PROXY,$ proxy);
如果有人在Windows网络上使用visual php连接到网站时遇到问题,希望能提供帮助