2013-08-30 130 views
1

嗨我試圖通過CURL發送POST請求,但它拋出一個錯誤,說
「無法連接到qaservices.carrental.com:443;沒有錯誤」。驗證卷曲HTTP發佈

的用戶名和密碼已經被包含在一個XML文件

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

SOAP頭當我嘗試發送的HttpWebRequest在vb.net這工作。在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

從curl/php的互聯網連接請求被拒絕的Windows服務器。一些非微軟應用程序,如fiddler,esclipse,maven不會連接到互聯網,如果你的電腦連接到windows網絡。您需要安裝cntlm代理,它會爲您添加一個標題,以便連接到互聯網。 我已配置cntlm以查看端口3127

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

希望這有助於如果有人有問題連接到網絡使用Windows網絡上的視覺PHP

0

都在SSL證書兩種主機上有效,你的節點?如果不是,則添加以下選項。這將繞過SSL驗證,並讓你連接

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

我試過了,但仍然沒有工作 – Neo

+0

粘貼的print_r的'輸出(curl_getinfo($ soap_do));' –

+0

Array([url] => https://qaservices.carrental.com/wsbang/HTTPSOAPRouter/ws9071 [content_type] => [http_code] => 0 [header_size] => 0 [request_size] => 0 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 1.498 [namelookup_time] => 0.499 [connect_time] => 0 [pretransfer_time] => 0 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => -1 [starttransfer_time] => 0 [redirect_time] => 0 [certinfo] => Array()[primary_ip] = > 170。 225.0.83 [primary_port] => 443 – Neo