Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Update a File by Rest API with PHP

Stefan Götschmann March 21, 2019

Hi there

I'd like to update an existing File in Bitbucket per curl. Here is my Code:

$headers = array(
'Accept: application/json',
'Content-Type: application/json'
);

$new_data['branch'] = 'master';
$new_data['content'] = '';
$new_data['message'] = 'Erstellen Testfile via Curl';
$new_data['sourceCommitId'] = '88618f2f116';

 

$url = $gitbucket_url."/projects/KI_FAHRPLAN/repos/journey-monitor/browse/src/config.list";
$ch = curl_init();
$jdata = json_encode($new_data);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $jdata);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, $user:$password);

$result = curl_exec($ch);

$ch_error = curl_error($ch);
if ($ch_error) {
echo "cURL Error: $ch_error";
}

$info = curl_getinfo($ch);

curl_close($ch);

 

I get the following answer:

 array(26) { ["url"]=> string(98) "https://****/rest/api/1.0/projects/KI_FAHRPLAN/repos/journey-monitor/browse/src/config.list" ["content_type"]=> string(30) "application/json;charset=UTF-8" ["http_code"]=> int(415) ["header_size"]=> int(329) ["request_size"]=> int(344) ["filetime"]=> int(-1) ["ssl_verify_result"]=> int(20) ["redirect_count"]=> int(0) ["total_time"]=> float(0.157) ["namelookup_time"]=> float(0.032) ["connect_time"]=> float(0.047) ["pretransfer_time"]=> float(0.063) ["size_upload"]=> float(103) ["size_download"]=> float(0) ["speed_download"]=> float(0) ["speed_upload"]=> float(656) ["download_content_length"]=> float(-1) ["upload_content_length"]=> float(103) ["starttransfer_time"]=> float(0.157) ["redirect_time"]=> float(0) ["redirect_url"]=> string(0) "" ["primary_ip"]=> string(13) "10.171.161.30" ["certinfo"]=> array(0) { } ["primary_port"]=> int(443) ["local_ip"]=> string(13) "10.123.240.37" ["local_port"]=> int(52818) }

 

415 means that it must a problem with the content_type. How i can change?

 

Thanks

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events