php
  • html
  • xml
  • curl
  • 2011-10-14 9 views 0 likes 
    0

    가능한 중복 :
    XML response from asp pageXML 응답

    내가 ASP 내 PHP 페이지에 출력 응답 CURL을 사용하는 PHP에서 XML 메시지를 보내려고하지만 운이없는 한 어떤 응답을받을 때. 이것은 내가 시도한 것입니다 :

    <?php 
    
    $post_string = "xmlmessage=<?xml version='1.0' encoding='UTF-8'?> 
    $url = "https://someweb.asp"; 
    <abc> 
    <UserId>123</UserId> 
    </abc>"; 
    
    //$header = "POST HTTPS/1.0 \r\n"; 
    $header = "Content-type: text/xml \r\n"; 
    $header .= "Content-length: ".strlen($post_string)." \r\n"; 
    $header .= "Content-transfer-encoding: text \r\n"; 
    $header .= "Connection: close \r\n\r\n"; 
    $header .= $post_string; 
    
    $ch = curl_init($url); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
    curl_setopt($ch, CURLOPT_URL,$url); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 4); 
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header); 
    
    $output = curl_exec($ch); 
    $info = curl_getinfo($ch); 
    
    if ($output == false || $info['http_code'] != 200) { 
        $output = "No cURL data returned for $url [". $info['http_code']. "]"; 
        if (curl_error($ch)) 
        $output .= "\n". curl_error($ch); 
        } 
    else 
        {curl_close($ch);} 
    
    echo $output; 
    ?> 
    

    누구든지 나를 잘못 안내 할 수 있습니까?

    답변

    1

    시도 :

    <?php 
    //do not put the $url within the XML (like in your original post) 
    $url = "https://someweb.asp"; 
    
    $post_string =<<<XML 
    <?xml version='1.0' encoding='UTF-8'?> 
    <abc> 
    <UserId>123</UserId> 
    </abc> 
    XML; 
    
    $post_string='xmlmessage='.rawurlencode($post_string); 
    echo $post_string; 
    
    /* 
    //$header = "POST HTTPS/1.0 \r\n"; 
    $header = "Content-type: text/xml \r\n"; 
    $header .= "Content-length: ".strlen($post_string)." \r\n"; 
    $header .= "Content-transfer-encoding: text \r\n"; 
    $header .= "Connection: close \r\n\r\n"; 
    $header .= $post_string; 
    */ 
    
    $ch = curl_init($url); 
    
    
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
    curl_setopt($ch, CURLOPT_URL,$url); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 4); 
    
    //get rid of the following and use the POST headers  
    //curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header); 
    
    //add the following two headers (for POST requests) 
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_POSTFIELDS,$post_string); 
    
    $output = curl_exec($ch); 
    $info = curl_getinfo($ch); 
    
    if ($output == false || $info['http_code'] != 200) { 
        $output = "No cURL data returned for $url [". $info['http_code']. "]"; 
        if (curl_error($ch)) 
        $output .= "\n". curl_error($ch); 
        } 
    else 
        {curl_close($ch);} 
    
    echo $output; 
    ?> 
    
    +0

    내가 지금 SSL의 conection에 제한을받을. 도와 주셔서 감사합니다 – user994144

    +0

    위의 SSL 연결에서 제공된 코드를 테스트 한 결과 제대로 작동합니다. 아마도 다음과 같은 도움이 될 수 있습니다. http://www.sitecrafting.com/blog/php-curl-ssl-connection-timeout/ – Hielo

    +0

    curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, 0)를 추가 했습니까? 코드에? http://stackoverflow.com/questions/7772146/xml-response-error에서 해당 옵션을 사용하지 않는 것을 확인했습니다. – Hielo

    관련 문제