Код: Выделить всё
Route::get('/getworkitem', function() {
$response = Http::withBasicAuth('Username', 'PAT')
->get('https://dev.azure.com/{Organisation}/{Project}/_apis/wit/workitems/32?fields=System.WorkItemType,System.AssignedTo&$expand=Links&api-version=5.1');
return $response;
});
Код: Выделить всё
Route::get('/add', function() {
$requiredata = array (
'op' => 'add',
'path' => '/fields/System.Title',
'from' => null,
'value' => 'Sample Task'
);
$response = Http::withBasicAuth('Username', 'PAT')->withHeaders([
'Content-Type' => 'application/json-patch+json',
])->post('https://dev.azure.com/Oraganisation/{Project}/_apis/wit/workitems/$issue?api-version=5.1', [
'body' => json_encode($requiredata,JSON_UNESCAPED_SLASHES)
]);
dd(json_decode($response->getBody()));
});
Код: Выделить всё
+"$id": "1"
+"innerException": null
+"message": "You must pass a valid patch document in the body of the request."
+"typeName": "Microsoft.VisualStudio.Services.Common.VssPropertyValidationException, Microsoft.VisualStudio.Services.Common"
+"typeKey": "VssPropertyValidationException"
+"errorCode": 0
+"eventId": 3000
Затем я попытался выполнить запрос через Guzzle, используя следующее:
Код: Выделить всё
Route::get('/add2', function() {
$headers = [
'Content-Type' => 'application/json-patch+json',
];
$body = [
'op' => 'add',
'path' => '/fields/System.Title',
'from' => null,
'value' => 'Sample Task'
];
$body = json_encode($body,JSON_UNESCAPED_SLASHES);
$client = new Client();
$res = $client->request('POST', 'https://dev.azure.com/{Organisation}/{Project}/_apis/wit/workitems/$Issue?api-version=5.1', [
'auth' => 'Username', 'Password'
], $headers, $body);
dd(json_decode($res->getBody()));
});
Мне удалось заставить POST-запрос работать в Почтальон, но не на PHP. Я просмотрел Google и не нашел ничего, что указывало бы на то, что я сделал неправильно, но если кто-то сможет указать мне правильное направление, почему он работает как GET, а не как POST, это было бы очень признательно.
Подробнее здесь: https://stackoverflow.com/questions/615 ... h-document
Мобильная версия