简体   繁体   English

Ruby Net :: HTTP无法正确获取网址

[英]Ruby Net::HTTP can't get url right

The code: 编码:

self.response = Net::HTTP.get_response(URI.parse(url.strip))

The url: 网址:

http://www.apmebf.com/g7116vpyxF/pw0/EDDEGMFH/EGJFDKJ/D/D/D?h=q<<lxxt%3A%2F%2F000.htfspz0.rix%3AC4%2Fgpmgo-57A64BA-54457D68<<K<<

Gives this error: 给出此错误:

bad URI(is not URI?)

I tried using URI.encode but then it throws this error: 我尝试使用URI.encode但随后抛出此错误:

undefined method `request_uri' for #<URI::Generic:0x007fc7ae31ecf0>

It's driving me nuts -- any ideas? 它让我发疯-有什么想法吗?

If you urlencode the URL you get 如果您对URL进行urlencode,则会得到

http%3A%2F%2Fwww.apmebf.com%2Fg7116vpyxF%2Fpw0%2FEDDEGMFH%2FEGJFDKJ%2FD%2FD%2FD%3Fh%3Dq%3C%3Clxxt%253A%252F%252F000.htfspz0.rix%253AC4%252Fgpmgo-57A64BA-54457D68%3C%3CK%3C%3C

Ruby can't find a protocol in there, so it assumes it is a generic URI and not an HTTP-URI. Ruby在此处找不到协议,因此假定它是通用URI,而不是HTTP-URI。 Only HTTP-URIs have a request_uri method. 仅HTTP-URI具有request_uri方法。

You'll have to fix that URI manually by replacing the < with %3C via str.replace . 您必须通过str.replace<替换为%3C来手动修复URI。

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

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