user1049097
user1049097

Reputation: 1901

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:

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

It's driving me nuts -- any ideas?

Upvotes: 0

Views: 721

Answers (1)

Marcel Jackwerth
Marcel Jackwerth

Reputation: 54782

If you urlencode the URL you get

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. Only HTTP-URIs have a request_uri method.

You'll have to fix that URI manually by replacing the < with %3C via str.replace.

Upvotes: 1

Related Questions