Hi
I've encountered a slight problem trying to use URLWRITE with 'get' parameters.
keyStr = 'Fmjtd%7Cluubnuur2h%xxxxxxxxxxx'; % not a real key
params = {'key' keyStr};
Now with appropriate url and filename I try:
[~,status] = urlwrite(url,filename,'get',params);
But URLWRITE calls java.net.URLEncoder.encode on the params so %'s are turned into %25, and of course the key fails.
How can I escape the url encoding? I've tried '%%' and '\%' but neither work.
Any ideas appreciated.
Neil

2 件のコメント

Walter Roberson
Walter Roberson 2013 年 10 月 18 日
Is the %7C intended to be interpreted on the other end as literally '%' '7' 'C', or is it intended that the other end decode it to character #252 ?
Neil Caithness
Neil Caithness 2013 年 10 月 21 日
Yes, the content of the key needs to be passed literally, without url encoding.

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

 採用された回答

Friedrich
Friedrich 2013 年 10 月 21 日

1 投票

Hi,
you can't. Look at the rules which are applied:
"All other characters are unsafe and are first converted into one or more bytes using some encoding scheme. Then each byte is represented by the 3-character string "%xy", where xy is the two-digit hexadecimal representation of the byte."
Seems like you need your own customized version of urlwrite here.

4 件のコメント

Neil Caithness
Neil Caithness 2013 年 10 月 21 日
Thanks. Yes, I've written a custom URLWRITE, if the parameter name is 'key' then skip the url encoding. Very hacky!
I guess the receiving web-service is not standards compliant. In this case http://open.mapquestapi.com/staticmap/wizard.html which insists that unsafe characters in the key are not encoded.
Neil Caithness
Neil Caithness 2013 年 10 月 22 日
I was just checking what Mapquest say in their API documentation and they do have this line - 'Please note that these key/value pairs must be properly URL-encoded.' I'm sure they understand more about this stuff than I do, but if I inset a raw key into their demo URLs it works, if I substitute %25 for each % (just as URLWRITE does) then it doesn't work.
So my question is: Is URLWRITE doing what is proper, and in this case I go with a hacky solution?
Walter Roberson
Walter Roberson 2013 年 10 月 22 日
I would substitute char(252) for the %7C in your string, and then let the url encoder transform it to %7c
Neil Caithness
Neil Caithness 2013 年 10 月 23 日
Walter, of course. Nice suggestion. Thanks

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

その他の回答 (0 件)

カテゴリ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by