URL encoding function

45 ビュー (過去 30 日間)
Eugene Kogan
Eugene Kogan 2011 年 8 月 3 日
編集済み: Walter Roberson 2023 年 12 月 14 日
Hi all,
I need to convert a string into a URL. I'm trying to use the urlencode function but it doesn't work properly, converting spaces to plus signs instead of the escape sequence %20. How can I convert the string properly, so space becomes %20 and other non-alphanumeric characters are replaced by their corresponding escape sequences?

回答 (4 件)

Fangjun Jiang
Fangjun Jiang 2011 年 8 月 4 日
Yes, it is weird. urlencode() is an one-line function. type "edit urlencode.m" to see if you can change the encoding method and then try again.
>> urlencode('http://www.mathworks.com/matlabcentral')
ans =
http%3A%2F%2Fwww.mathworks.com%2Fmatlabcentral
  1 件のコメント
Paulo Silva
Paulo Silva 2011 年 8 月 4 日
編集済み: Walter Roberson 2023 年 12 月 14 日

サインインしてコメントする。


Morrie Gasser
Morrie Gasser 2017 年 2 月 6 日
If you are using the encoded result for a URI or URL, note that in R2016b there is a new class, matlab.net.URI, which may do the encoding you're looking for.
  2 件のコメント
Tom Hawkins
Tom Hawkins 2019 年 11 月 19 日
matlab.net.URI also appears to encode spaces (in query parameters etc) as + characters instead of %20.
Sean
Sean 2023 年 12 月 14 日
That is also what I am seeing in 2023b.
tst = matlab.net.URI('http://2.2.2.2:20000', 'stringVal', 'test string');
tst.EncodedURI
ans =
"http://2.2.2.2:20000?stringVal=test+string"

サインインしてコメントする。


Muhammad Siddiqui
Muhammad Siddiqui 2020 年 4 月 26 日
I'm trying to detect SQL injection in my course of Pattern Recognition. My algorithm would be as follows:-
1) Encode URL feeded by user (this step is feature detection)
2) Compare the URL with the dataset of false URL.
3) Accordingly, classify whether URL is vulnerable or otherwise.
Please help me in writing code for above-stated steps. Prompt assistance is requested

Bereketab Gulai
Bereketab Gulai 2020 年 4 月 28 日
編集済み: Bereketab Gulai 2020 年 4 月 28 日
Here is an anternative,
Using mlreportgen.utils.fileToURI
report = getReport(x, 'extended', 'hyperlinks', 'off');
% Take some of the report beginning, replace
% spaces, they will be encoded (NOTE: potential other things may be encoded which could fail)
reportBeginningText = strrep(extractBetween(report, 1, 10), ' ', '%20');
% mlreportgen.utils.fileToURI is the only correct provider of encoded path, I suppose.
% However, "file:/c:/some/path" needs to be removed
formattedReport = reportBeginningText + extractAfter(mlreportgen.utils.fileToURI(report), reportBeginningText);
This example was used with mailto URL.

カテゴリ

Help Center および File ExchangeCall 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!

Translated by