Is there a best practice for enconding URI on the REST API communication from MATLAB?
古いコメントを表示
Hi, I'm working on a project, where JSon::API-based communication is happening from MATLAB.
I'm getting to the point, where the URI, which I passing to the 'send' method gets encoded by MATLAB. Is there a way to disable this conversion?
Particularly, here is my code:
request = matlab.net.http.RequestMessage();
request.Method = options.method;
request.Header = [ ...
matlab.net.http.field.ContentTypeField( 'application/json' ), ...
matlab.net.http.field.AcceptField( 'application/json' ), ...
matlab.net.http.field.AuthorizationField('Authorization', ['Bearer ' PAT]), ...
];
httpOptions = matlab.net.http.HTTPOptions('ResponseTimeout', remoteOperationTimeOut);
[response, completedRequest] = request.send(finalPoint, httpOptions)
where finalPoint is 'https://<xxx-server>/rest/v1/projects/NickTest/spaces/Testing/documents/Big document for testing REST/parts'
Note the spaces in the URL.
When I check the completedRequest, I see that this URL was post-processed:
RequestMessage with properties:
Method: GET
RequestLine: 'GET /rest/v1/projects/NickTest/spaces/Testing/documents/Big%20document%20for%20testing%20REST/parts HTTP/1.1'
Header: [1×7 matlab.net.http.HeaderField]
Body: [0×0 matlab.net.http.MessageBody]
Completed: 1
note, that the RequestLine has converted spaces to the '%20'. That's all fine so far.
However, I'm working with the pagination feature, and server returns to me some links how to request next page of the response.
And this links already contain %20 instead of the space, so passing to 'request.send(newURL)' makes a double encoding, and it works wrongly (not found).
For now, before sending the consequent request, I'm converting back %20 to spaces:
nextPageLink = strrep(addition.links.next, '%20', ' ');
but this sounds wrong to me - on the client I don't want to alter any URLs, that server returns to me.
Is there any flag or option to prevent double conversion, and leaving URIs as-is?
Thank you in advance!
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Call Web Services from MATLAB Using HTTP についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!