bonjour je dois faire un appel post vers une serveur pour mettre à jour des datas
je fait un 1er appel afin de recupérer un Bearer , cela fonctionne dans Delphi
puis un second appel pour faire la MAJ des données et là alors que ça fonctionne sans souci dans postman , dans powershell impossible de le faire fonctionner dans débogueur REST 12.0 ni dans Delphi
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]" $headers.Add("Authorization", "Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMyIsImF1dGgiOiJBZG1pbmlzdHJhdGV1ciIsIm9yZ0NvZGUiOiI0NDUiLCJhdXRoZW50RGF0ZVRpbWUiOiIyMDI2MDMxNzA5MjIwOCIsImV4cCI6MTc3MzgyNTcyOH0.U44uVs-aopxqLf-cmvREwjSvwxo57NrK6QAn21WeerU") $headers.Add("Content-Type", "application/json") $body = @" { `"documentNumber`": `"V445013-0000001`", `"orderType`": `"VAD`", `"paymentDetails`": [ { `"lineNumber`": `"1`", `"amount`": `"1`", `"paymentMethod`": `"ZZ26`" }, { `"lineNumber`": `"2`", `"amount`": `"1`", `"paymentMethod`": `"ZZ26`" } ] } "@ $response = Invoke-RestMethod 'https://api.ptsrc.adeiz.com/services/orderservice/api/v1/sales-orders-lite' -Method 'POST' -Headers $headers -Body $body $response | ConvertTo-Json]Le bearer est différent car récupérer à chaque fois
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89 procedure SendSalesOrder; var RESTClient: TRESTClient; RESTRequest: TRESTRequest; RESTResponse: TRESTResponse; paymentDetailsArray:tjsonarray; jsonBody, payment1, payment2: TJSONObject; jsonObject, paymentDetailsObject: TJSONObject; begin // Créer le client REST RESTClient := TRESTClient.Create(nil); try RESTClient.BaseURL := 'https://api.ptsrc.adeiz.com/services/orderservice/api/v1/sales-orders-lite'; // Créer la requête RESTRequest := TRESTRequest.Create(nil); try RESTRequest.Client := RESTClient; RESTRequest.Method := rmPOST; // Ajouter les en-têtes // restrequest.AddParameter('Authorization'); restrequest.AddParameter('"Authorization"','"Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMyIsImF1dGgiOiJBZG1pbmlzdHJhdGV1ciIsIm9yZ0NvZGUiOiI0NDUiLCJhdXRoZW50RGF0ZVRpbWUiOiIyMDI2MDMxNzEzMjIzMCIsImV4cCI6MTc3Mzg0MDE1MH0.tIflejQyPcCKp52zPRhYCuiSB0XMkHLIAHyoF*****"',pkHTTPHEADER); // RESTRequest.AddHeader('Authorization', 'Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMyIsImF1dGgiOiJBZG1pbmlzdHJhdGV1ciIsIm9yZ0NvZGUiOiI0NDUiLCJhdXRoZW50RGF0ZVRpbWUiOiIyMDI2MDMxNzA5MjIwOCIsImV4cCI6MTc3MzgyNTcyOH0.U44uVs-aopxqLf-cmvREwjSvwxo57NrK6QAn21*****'); RESTRequest.Addparameter('Content-Type', 'application/json'); // Construire le corps JSON jsonBody := TJSONobject.Create; // Créer la partie principale jsonObject := TJSONObject.Create; try jsonObject.AddPair('documentNumber', 'V445013-0000001'); jsonObject.AddPair('orderType', 'VAD'); // PaymentDetails array paymentDetailsArray := TJSONarray.Create; // Payment 1 payment1 := TJSONObject.Create; payment1.AddPair('lineNumber', '1'); payment1.AddPair('amount', '1'); payment1.AddPair('paymentMethod', 'ZZ26'); // Payment 2 payment2 := TJSONObject.Create; payment2.AddPair('lineNumber', '2'); payment2.AddPair('amount', '1'); payment2.AddPair('paymentMethod', 'ZZ26'); paymentDetailsArray.Add(payment1); paymentDetailsArray.Add(payment2); jsonObject.AddPair('paymentDetails', paymentDetailsArray); // Convertir en string jsonBody:=jsonObject; finally // Libérer les objets temporaires // Note: jsonObject, paymentDetailsArray, payment1, payment2 sont ajoutés à jsonBody // et seront libérés avec jsonBody si on ne les libère pas ici end; // Définir le corps de la requête restrequest.AddBody(jsonBody.ToString); // RESTRequest.Body := TEncoding.UTF8.GetBytes(jsonBody.ToString); // RESTRequest.ContentType:=application/json; // Exécuter la requête RESTResponse := TRESTResponse.Create(nil); try RESTRequest.Response := RESTResponse; RESTRequest.Execute; // Traiter la réponse // showmessage ('Réponse: ', RESTResponse.Content); form5.memo1.lines.add(RESTResponse.Content); finally RESTResponse.Free; end; finally RESTRequest.Free; end; finally RESTClient.Free; end; end;
et là l'export de REST DEBOGUEUR
je ne comprend pas pourquoi j'ai toujours cette erreur en Ddelphi ou REST debogueur
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 object RESTClient1: TRESTClient BaseURL = 'https://api.ptsrc.adeiz.com/services/orderservice/api/v1/sales-o' + 'rders-lite' Params = <> SynchronizedEvents = False end object RESTRequest1: TRESTRequest AssignedValues = [rvConnectTimeout, rvReadTimeout] Client = RESTClient1 Method = rmPOST Params = < item Kind = pkHTTPHEADER Name = 'Authorization' Options = [poDoNotEncode] Value = 'Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMyIsImF1dGgiOiJBZG1pbmlz' + 'dHJhdGV1ciIsIm9yZ0NvZGUiOiI0NDUiLCJhdXRoZW50RGF0ZVRpbWUiOiIyMDI2' + 'MDMxNjE0MjMxOSIsImV4cCI6MTc3Mzc1NzM5OX0.esg-OQXCTo_Nwke8G_6HkuGM' + 'dGa3g3Z7b0uK5mrH_xY' end item Kind = pkREQUESTBODY Name = 'bodyB6827D9362784EE6BA295D02118AD896' Value = 'bodyB6827D9362784EE6BA295D02118AD896{'#13#10' "documentNumber": "V445013-0000001",'#13#10' "orderType": "VAD",' + #13#10' "paymentDetails": ['#13#10' {'#13#10' "lineNumber": "1",'#13#10' ' + '"amount": "1",'#13#10' "paymentMethod": "ZZ26"'#13#10' },'#13#10' {'#13#10' ' + ' "lineNumber": "2",'#13#10' "amount": "1",'#13#10' "paymentMet' + 'hod": "ZZ26"'#13#10' }'#13#10' ]'#13#10'}' ContentTypeStr = 'application/json' end> Response = RESTResponse1 SynchronizedEvents = False end object RESTResponse1: TRESTResponse end
{"status ":"UNAUTHORIZED","statusCode":"401 Unauthorized","ExceptionType":"org.springframework.security.authentication.InsufficientAuthenticationException","message":"Full authentication is required to access this resource","path":"/api/v1/sales-orders-lite","resourceVarName":""}





Répondre avec citation








?

Partager