2012-05-10 68 views
-1

我需要在沒有CuRL的情況下POST xml數據。POST xml不使用CURL

有很多片段,但似乎沒有任何工作。 最新的嘗試:

function salesOrder($xml, $url) 
{ 

    $context = stream_context_create(array(
    'http' => array(
     'method' => 'POST', 
     'header' => "Content-type: application/xml\r\n", 
     'content' => $xml, 
     'timeout' => 5, 
    ), 
)); 
    $ret = file_get_contents($url, false, $context); 

    return false !== $ret; 
} 

什麼也沒有返回空白頁。

我已經試過http://wezfurlong.org/blog/2006/nov/http-post-from-php-without-curl/

問題是,我真的不理解它,我似乎無法找到一個很好的教程,涵蓋了這個問題。任何人都可以將我指向正確的方向嗎?

+1

不要說 「它不工作」,因爲它不是描述。說出你期望發生的事情,以及實際發生的事情,並且非常具體。無論如何,打開錯誤報告並檢查錯誤日誌。你需要學習基本的調試技術。 – goat

+1

cURL有什麼問題?這有點像說「我需要砍掉一棵樹,沒有任何尖銳物體。」 – ceejayoz

回答

1

您可以用它來實現這一

$xml = "<xml><name>hello</name></xml>" ; 
$opts = array (
     'http' => array (
       'method' => "POST", 
       'content' => $xml, 
       'timeout' => 5, 
       'header' => "Content-Type: text/xml; charset=utf-8" 
     ) 
); 

$context = stream_context_create ($opts); 
$fp = fopen ('http://example.com/b.php', 'r', false, $context); 
fpassthru ($fp); 
fclose ($fp); 

http://example.com/b.php

file_put_contents("php://output", file_get_contents("php://input")); 
+0

你能解釋我在做什麼file_put_contents? –

+0

你正在用'file_get_contents(「php:// input」)''讀入傳入的數據,然後用'file_put_contents(「php:// output」'「]寫回來。如果你在瀏覽器上運行這個數據,你會看到滿被髮送的xml文件 – Baba

+0

是的......它會接受帖子 – Baba