Can I make the matlab http send function to use "%40" in the destination url?
Show older comments
I need to send a PUT or POST request to a url containing '%40' (encoded "@" symbol) in the destination url. I need to use the matlab.net.http send function in order to get information from the response headers.
I am not an expert on http. My problem is that regardless how I try to structure the message and send function, the sent request either includes the unencoded "@" symbol or the double-encoded '%2540', both of which trigger errors from the server.
Is there a way to force the send function to use '%40' in the destination address?
I am providing a dummy example below to show the issue because the real url (from Adobe API) is extremely long and contains API keys.
Grateful for any help on this.
import matlab.net.*
import matlab.net.http.*
% URL- NOTICE THE REQUIRED ENCODED %40 which is encoded symbol "@"
exampleURL = 'https://www.example.com/abcd%40efgh.com/ijkl?queryString=queryValue';
exampleURL_components = URI(exampleURL,'literal');
% Construct a dummy request message. This does not depend on the url.
exampleRequest = RequestMessage('PUT',[], "Irrelevant");
% Send the dummy request to original URL - The symbol "@" is DOUBLE ENCODED - causes error
[~,sentrequest,~] = send(exampleRequest,exampleURL);
disp('Sent request contains double-encoding from @ to %2540');
disp(sentrequest.RequestLine.RequestTarget);
% Send the dummy request to URI - The symbol "@" is UNENCODED - causes error
[~,sentrequest2,~] = send(exampleRequest,exampleURL_components);
disp('Sent request contains unencoded @');
disp(sentrequest2.RequestLine.RequestTarget);
1 Comment
Assen Koev
on 11 Nov 2024
Edited: Assen Koev
on 11 Nov 2024
Answers (1)
Sreeram
on 18 Nov 2024
0 votes
MATLAB’s HTTP interface does not provide an option to disable encoding or force the “send” function to use a URL. The “send” function ensures that the URL is valid according to the encoding rules.
According to RFC 3986, the path of a URI may consist of characters in ‘segment-nz-nc’ and this set lists the ‘@’ character explicitly:
segment-nz-nc = 1*( unreserved / pct-encoded / sub-delims / "@" )
So, the HTTP URI displayed in the last line of the code you shared is valid. You might want to consider double checking why this causes the error.
Thanks
1 Comment
Assen Koev
on 20 Nov 2024
Categories
Find more on Call Web Services from MATLAB Using HTTP in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!