[問題] Vertical Bar in URL (網址中有'|')

看板Ruby作者 (hello)時間13年前 (2011/11/06 13:31), 編輯推噓0(003)
留言3則, 2人參與, 最新討論串1/1
環境: Ruby 1.9.2 狀況: 網址中有vertical bar '|' 會被ruby判定為invalid URI 附錄: require 'net/http' #url內有'|'符號!瀏覽器可接受此網址,但ruby無法get該網頁內容 url = http://maps.google.com/maps/api/directions/json?sensor=false&origin=New+York+City,+USA&destination=Washington+DC,+USA&waypoints=optimize:true|Philadelphia,+PA|Newark,+NJ Net::HTTP.get(::URI.parse(url)) 錯誤訊息: D:/Ruby192/lib/ruby/1.9.1/uri/common.rb:156:in `split': bad URI(is not URI?): ht tp://maps.google.com/maps/api/directions/json?sensor=false&origin=New+York+City, +USA&destination=Washington+DC,+USA&waypoints=optimize:true|Philadelphia,+PA|New ark,+NJ (URI::InvalidURIError) from D:/Ruby192/lib/ruby/1.9.1/uri/common.rb:174:in `parse' from D:/Ruby192/lib/ruby/1.9.1/uri/common.rb:628:in `parse' from xmlReader.rb:70:in `get_url' from xmlReader.rb:55:in `xml' from xmlReader.rb:47:in `find_status' from xmlReader.rb:43:in `initialize' from xmlReader.rb:83:in `new' from xmlReader.rb:83:in `<main>' shell returned 1 請問該如何解決? 感謝! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 96.32.170.168

11/06 13:53, , 1F
找到答案了!把'|'換成'%7D'就可以了!
11/06 13:53, 1F

11/06 14:25, , 2F
更正 是%7C
11/06 14:25, 2F

11/06 16:43, , 3F
那是因為瀏覽器能容錯,那個符合應該要被編碼起來
11/06 16:43, 3F
文章代碼(AID): #1EjXl4hW (Ruby)
文章代碼(AID): #1EjXl4hW (Ruby)