简体   繁体   English

验证Curl HTTP发布

[英]Authenticating Curl HTTP Post

Hi I am trying to send POST request through CURL but its throwing an error which says 嗨,我正在尝试通过CURL发送POST请求,但是它引发了一个错误,提示说
"Failed connect to qaservices.carrental.com:443; No error". “无法连接到qaservices.carrental.com:443;没有错误”。

The username and password is already included in the soap header in an xml file 用户名和密码已经包含在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;
?>

When i try to send HttpWebRequest in vb.net this works. 当我尝试在vb.net中发送HttpWebRequest时,此方法有效。 the copy of code in vb.net is 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

I think it has to do something in setting up proxy credential Can anyone please guide me in correct path 我认为它必须在设置代理凭证方面有所作为,有人可以指导我正确的方法吗?

Are both the SSL certificates valid on both host and your node? SSL证书在主机和您的节点上均有效吗? If not, then add the following options. 如果不是,则添加以下选项。 This will bypass SSL verification and let you connect 这将绕过SSL验证,并让您连接

curl_setopt ($soap_do, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($soap_do, CURLOPT_SSL_VERIFYPEER, 0); 

A request for internet connection from curl/php was refused the windows server. 来自curl / php的Internet连接请求被Windows服务器拒绝。 Some non microsoft application like fiddler, esclipse , maven will not connect to internet if your pc is connected to windows network. 如果您的PC连接到Windows网络,则某些非Microsoft应用程序(例如fiddler,esclipse,maven)将无法连接到Internet。 You need to install cntlm proxy which will add a header to you request so it can connect to internet. 您需要安装cntlm代理,它将向您的请求添加标头,以便它可以连接到Internet。 I have configured cntlm to look on port 3127 我已配置cntlm以查看端口3127

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

Hope this help if someone is having a problem to connect to web using visual php on windows network 如果有人在使用Windows网络上的可视php连接到Web时遇到问题,希望对您有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM