# Using ruby Net::HTTP with self signed certificates

**URL:** <https://www.ruby-forum.com/t/using-ruby-net-http-with-self-signed-certificates/127479>\
**Category:** Rails\
**Created:** [January 29, 2008, 6:06pm UTC](https://www.ruby-forum.com/t/using-ruby-net-http-with-self-signed-certificates/127479 "2008-01-29T18:06:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [January 29, 2008, 6:06pm UTC](https://www.ruby-forum.com/t/using-ruby-net-http-with-self-signed-certificates/127479/1 "2008-01-29T18:06:47Z")

</div>

Probably more of a ruby question than a rails question but I am trying  
to retrieve a file from my web server that requires ssl but uses a self  
signed certificate.

Looking through all of the documentation at  
[http://www.ruby-doc.org/stdlib/libdoc/net/http/rdoc/index.html](http://www.ruby-doc.org/stdlib/libdoc/net/http/rdoc/index.html)  
and  
[http://www.ruby-doc.org/stdlib/libdoc/net/http/rdoc/classes/Net/HTTP.html](http://www.ruby-doc.org/stdlib/libdoc/net/http/rdoc/classes/Net/HTTP.html)

I don’t see any way that I could do something equivalent to like wget…

wget -no-check-certificate [https://myserver/myfile.txt](https://myserver/myfile.txt)

Is there any way to accomplish this with net/http or do I have to  
execute a shell wget and open the file locally?

Craig

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [January 29, 2008, 9:25pm UTC](https://www.ruby-forum.com/t/using-ruby-net-http-with-self-signed-certificates/127479/2 "2008-01-29T21:25:06Z")

</div>

On Tue, 2008-01-29 at 10:04 -0700, Craig W. wrote:

> wget -no-check-certificate [https://myserver/myfile.txt](https://myserver/myfile.txt)
> 
> Is there any way to accomplish this with net/http or do I have to  
> execute a shell wget and open the file locally?

* * *

OK, I think I have this solved but I’m hamstrung by a ‘?’ in the URL…

in console…

> > url.path =  
> > “/horde/kronolith/ics.php?c=5be410ec5238fc93c1f66b1a935365c9”  
> > URI::InvalidComponentError: bad component(expected absolute path  
> > component): /horde/kronolith/ics.php?c=5be410ec5238fc93c1f66b1a935365c9  
> > from /usr/lib/ruby/1.8/uri/generic.rb:475:in `check_path' from /usr/lib/ruby/1.8/uri/generic.rb:495:in `path=’  
> > from (irb):354  
> > from :0

and if I substitute %3F for the ? it will accept the ‘path’…

> > url.path = “/horde/kronolith/ics.php%  
> > 3Fc=5be410ec5238fc93c1f66b1a935365c9”  
> > =\> “/horde/kronolith/ics.php%3Fc=5be410ec5238fc93c1f66b1a935365c9”

but it doesn’t work

> > res = Net::HTTP.new(url.host, 443)  
> > =\> #\<Net::HTTP my\_server:443 open=false\>  
> > res.use\_ssl=true  
> > =\> true  
> > res.verify\_mode = OpenSSL::SSL::VERIFY\_NONE  
> > =\> 0  
> > ret=res.start {|http| http.request(req)}  
> > =\> #\<Net::HTTPBadRequest 400 Bad Request readbody=true\>

nor does this URL work with wget…

wget --no-check-certificate  
[https://craig](https://craig):\*\*\*\*\*@my\_server//horde/kronolith/ics.php%  
3Fc=5be410ec5238fc93c1f66b1a935365c9  
–13:06:07–  
[https://craig](https://craig):_password_@my\_server//horde/kronolith/ics.php%  
3Fc=5be410ec5238fc93c1f66b1a935365c9  
=\> `ics.php?c=5be410ec5238fc93c1f66b1a935365c9.1’  
Resolving my\_server… 192.168.3.5  
Connecting to my\_server|192.168.3.5|:443… connected.  
WARNING: Certificate verification error for my\_server: self signed  
certificate  
HTTP request sent, awaiting response… 404 Not Found  
13:06:07 ERROR 404: Not Found.

of course with a ? instead of %3F, it works

How does one use net/http (net/https) with URL’s that have a ?

?

Craig
