1

我是第一次尝试使用 php curl。我正在通过在 Bitbucket 问题跟踪器中创建问题来尝试此操作。

API 文档在下面显示为经过身份验证的用户的端点:

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

据说 curl 请求是这样的:

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);
4

2 回答 2

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);
于 2013-09-27T13:01:58.660 回答
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
于 2013-09-27T13:00:51.347 回答