http HeaderField request invalid
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
According to provided API, the request must include the following header:
x-http-request-info:{"clientRequestId":{"sessionId":"some_ID_number","requestId":"123456789"}}
If I use the webread, I can construct this as
requestId = struct('clientRequestId',struct('sessionId',sessionId,'requestId',requestId));
header = {'x-http-request-info' jsonencode(requestId)};
options = weboptions('RequestMethod','GET','HeaderFields',header);
response = webread(url, options);
The problem with this approach is that webread does not return response-header, so I have to use the low level http commands.
However matlab.net.http.RequestMessage does not accept the above request header. I have tried to use matlab.net.http.HeaderField:
field1 = matlab.net.http.HeaderField('sessionId', sessionId);
field2 = matlab.net.http.HeaderField('requestId', requestId);
requestInfo = matlab.net.http.HeaderField('clientRequestId',[field1, field2]);
matlab.net.http.HeaderField('x-http-request-info', requestInfo);
method = matlab.net.http.RequestMethod.GET;
request = matlab.net.http.RequestMessage(method,header);
response = send(request,uri);
The response comes back with code 400 BadRequest
response =
ResponseMessage with properties:
StatusLine: 'HTTP/1.1 400 '
StatusCode: BadRequest
Header: [1×8 matlab.net.http.HeaderField]
Body: [1×1 matlab.net.http.MessageBody]
Completed: 0
response.Body.Data.messages
ans =
struct with fields:
key: 'request.header.invalid.x-http-request-info'
severity: 'ERROR'
message: 'Der Header 'x-http-request-info' ist fehlerhaft.'
What is the correct way to specify this particular header?
Many thanks in advance!
Victor
0 commentaires
Réponses (1)
Suraj
le 14 Sep 2023
Hi Victor,
I see that you want to set a custom header for your GET request. “webread” method lets you do this however you mentioned that you want to use a lower-level HTTP method for the same.
I suggest that you checkout “urlread2” from the File Exchange: https://www.mathworks.com/matlabcentral/fileexchange/35693-urlread2
Thanks & regards,
Suraj.
0 commentaires
Voir également
Catégories
En savoir plus sur Call Web Services from MATLAB Using HTTP dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!