1

Hi I am trying to send POST request through CURL but its throwing an error which says
"Failed connect to qaservices.carrental.com:443; No error".

The username and password is already included in the soap header in an xml file

<?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;
?>

When i try to send HttpWebRequest in vb.net this works. the copy of code in vb.net is

       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

I think it has to do something in setting up proxy credential Can anyone please guide me in correct path

4

2 回答 2

0

来自 curl/php 的 Internet 连接请求被 Windows 服务器拒绝。如果您的电脑连接到 Windows 网络,一些非微软应用程序(如 fiddler、esclipse、maven)将无法连接到互联网。您需要安装 cntlm 代理,它将为您的请求添加一个标头,以便它可以连接到互联网。我已将 cntlm 配置为查看端口 3127

在上面的代码中,我添加了 $proxy = '127.0.0.1:3127'; curl_setopt($soap_do, CURLOPT_PROXY, $proxy);

如果有人在 Windows 网络上使用可视化 php 连接到网络时遇到问题,希望这能有所帮助

于 2013-09-04T02:30:10.877 回答
0

SSL 证书在主机和您的节点上都有效吗?如果没有,则添加以下选项。这将绕过 SSL 验证并让您连接

curl_setopt ($soap_do, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($soap_do, CURLOPT_SSL_VERIFYPEER, 0); 
于 2013-08-30T04:56:46.157 回答