使用特殊字符编码URL

时间:2017-03-03 17:48:33

标签: r url url-encoding


我有以下网址,其中value(C#)包含特殊内容 字符():

url <- "https://www.myurl.com/test?req=[{\"geo\":{},\"kw\":{\"keyword\":[{\"type\":\"BROAD\",\"value\":\"C#\"}]}}]"

使用URLencode()我希望将 C#转换为 C%23 得到:

"https://www.myurl.com/test?req=[%7B%22geo%22:%7B%7D,%22kw%22:%7B%22keyword%22:[%7B%22type%22:%22BROAD%22,%22value%22:%22C%23%22%7D]%7D%7D]"
#> [1] "https://www.myurl.com/test?req=[%7B%22geo%22:%7B%7D,%22kw%22:%7B%22keyword%22:[%7B%22type%22:%22BROAD%22,%22value%22:%22C%23%22%7D]%7D%7D]"

但是,我得到了:

URLencode(url)
#> [1] "https://www.myurl.com/test?req=[%7B%22geo%22:%7B%7D,%22kw%22:%7B%22keyword%22:[%7B%22type%22:%22BROAD%22,%22value%22:%22C#%22%7D]%7D%7D]"

我尝试使用reserved参数但没有成功。有没有办法对url进行编码以获得我期待的内容?

0 个答案:

没有答案