简体   繁体   English

C ++ REST SDK(“卡萨布兰卡”)中的URI编码

[英]URI encoding in C++ REST SDK (“Casablanca”)

I'm using the http listener of the C++ REST SDK 2.8 and noticed the following. 我正在使用C ++ REST SDK 2.8的http侦听器,并注意到以下内容。 If I send the following URL to this listener: 如果我将以下URL发送到此侦听器:

http://my_server/my%2fpath?key=xxx%26yyy%3Dzzz

and I do: 而我这样做:

auto uri = request.relative_uri();
auto v_path_components = web::uri::split_path(web::uri::decode(uri.path()));
auto m_query_components = web::uri::split_query(web::uri::decode(uri.query()));

then I find that v_path_components contains 2 elements ["my", "path"], and m_query_components contains 2 pairs [("key","xxx"), ("yyy","zzz")]. 那么我发现v_path_components包含2个元素[“ my”,“ path”],而m_query_components包含2对[[“ key”,“ xxx”),(“ yyy”,“ zzz”)]。

What I want and would have expected is v_path_components to contain 1 element ["my/path"], and m_query_components to contain 1 pair [("key","xxx&yyy=zzz")]. 我想要并且期望得到的是v_path_components包含1个元素[“ my / path”],而m_query_components包含1对[[“ key”,“ xxx&yyy = zzz”)]。

In order for the latter to achieve, relative_uri shouldn't decode/encode the uri, as that looses information. 为了使后者能够实现, relative_uri不应对uri进行解码/编码,因为这会丢失信息。 In addition, web::uri::decode() should be executed on the split results rather than before splitting. 此外,应在分割结果上而不是在分割之前执行web :: uri :: decode() But, as the REST SDK itself as well as many samples shipped with it uses this in the above way, it leads me to believe that I might be wrong. 但是,由于REST SDK本身以及随附的许多示例都以上述方式使用了此功能,因此使我相信我可能是错的。

Could anyone confirm my findings or explain why I'm on the wrong track? 谁能证实我的发现或解释我为什么走错路了?

Your findings make sense. 您的发现很有道理。

Since you are decoding first, then the encoded ampersand (%3D) becomes a key/value pair separator. 由于您先解码,因此编码后的与号(%3D)成为键/值对分隔符。 Same for the path components. 路径组件相同。 The slash (%2f) becomes a path separator, and is parsed as such. 斜杠(%2f)成为路径分隔符,并以此进行解析。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM