我是第一次尝试使用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)
没有得到你想要的问题。但这是你可以使用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
答案 1 :(得分: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);