2013-09-27 91 views
1

我第一次嘗試使用php curl。我嘗試通過在Bitbucket問題跟蹤器中創建問題。使用捲曲的帖子

API文檔下面顯示爲終點的身份驗證的用戶:

POST https://bitbucket.org/api/1.0/repositories/{accountname}/{repo_slug}/issues --data "title=value&content=value" 

而捲曲的請求被說成是這樣的:

curl -r POST --header "Content-Length: 0" -u user:pass https://bitbucket.org/api/1.0/repositories/{accountname}/{repo_slug}/issues --data "title=value&content=value 

我想用以下代碼:

$p = 'curl -r POST --header "Content-Length: 0" -u user:pass https://bitbucket.org/api/1.0/repositories/{accountname}/{repo_slug}/issues --data "title=value&content=value'; 

$ch = curl_init(); 
//execute post 
$result = curl_exec($point); 
//close connection 
curl_close($ch); 
+0

要哪一個環節要發佈?以及要發佈哪些數據? –

回答

1
<?php 
    //extract data from the post 
    extract($_POST); 

    //set POST variables 
    $url = 'http://domain.com/get-post.php'; 
    $fields = array(
          'lname' => urlencode($last_name), 
          'fname' => urlencode($first_name), 
          'title' => urlencode($title), 
          'company' => urlencode($institution), 
          'age' => urlencode($age), 
          'email' => urlencode($email), 
          'phone' => urlencode($phone) 
        ); 

    //url-ify the data for the POST 
    foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } 
    rtrim($fields_string, '&'); 

    //open connection 
    $ch = curl_init(); 

    //set the url, number of POST vars, POST data 
    curl_setopt($ch,CURLOPT_URL, $url); 
    curl_setopt($ch,CURLOPT_POST, count($fields)); 
    curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string); 

    //execute post 
    $result = curl_exec($ch); 

    //close connection 
    curl_close($ch); 
1

沒有正確地得到你想要的問題。但是,您可以通過curl將您的帖子字段鏈接到鏈接。

$path = "Your Path here, to which you are sending data"; 
$post_string = "Value you are posting"; //user=john&pass=test 

$ch = curl_init($path); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string); //Send the data to the path 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
$val = curl_exec($ch); 

curl_close($ch);//Close curl session