1

I use following code to send Get/Post request to my server, and the code could work well.


require "net/https"
require "openssl"
require "uri"

tenantID = "95bde077-58e8-b58351b28b8a"
url = "https://example.com:443/application/0.9/providers?_filter=keyIndexName=xxxxx"

headers = {
  "Content-Type" => "application/json",
  "X-TenantID" => tenantID,
}

uri = URI.parse(url)

http_client = Net::HTTP.new(uri.host, uri.port)
http_client.use_ssl = true if uri.scheme == "https"
http_client.verify_mode = OpenSSL::SSL::VERIFY_PEER

p12 = OpenSSL::PKCS12.new(File.read("./keyfile.p12"), "0K4xgXbpzJkMrpGLILp4ZD7ijcdOnOkC")
http_client.cert = p12.certificate
http_client.key = p12.key
ca_store = OpenSSL::X509::Store.new
ca_store.add_file "./ca.pem"

request = Net::HTTP::Get.new(uri.request_uri, initheader = headers)
http_client.set_debug_output $stderr
res = http_client.request(request)

puts res.code
puts res.body

But after I add a proxy to http_client like following

proxy_uri = URI.parse("https://proxy.xxx.com:443")

http_client = Net::HTTP.new(uri.host, uri.port, proxy_uri.host, proxy_uri.port)

The operation failed and always prompt

opening connection to proxy.xxx.com:443...
opened
<- "CONNECT example.com:443 HTTP/1.1\r\nHost: example.com.com:443\r\n\r\n"
-> "\x15\x03\x03\x00\x02\x02\n"
Conn close because of connect error wrong status line: "\x15\x03\x03\x00\x02\x02"
Traceback (most recent call last):
        6: from thread.rb:60:in `<main>'
        5: from /Users/xxxx/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/net/http.rb:1470:in `request'
        4: from /Users/xxxx/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/net/http.rb:919:in `start'
        3: from /Users/xxxx/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/net/http.rb:930:in `do_start'
        2: from /Users/xxxx/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/net/http.rb:969:in `connect'
        1: from /Users/xxxx/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/net/http/response.rb:29:in `read_new'
/Users/xxxx/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/net/http/response.rb:42:in `read_status_line': wrong status line: "\x15\x03\x03\x00\x02\x02" (Net::HTTPBadResponse)

I confirm that the proxy server does not set any user/password authentication. Why the proxy server always return the HTTPBadResponse. What's the meaning of the string "\x15\x03\x03\x00\x02\x02"?

anothermh
  • 9,815
  • 3
  • 33
  • 52
dp9463
  • 11
  • 2
  • No need to prefix your post title with "Ruby - " -- that's what [tags](https://stackoverflow.com/help/tagging) are for. – anothermh Feb 11 '20 at 18:04
  • See https://stackoverflow.com/a/31603073/3784008. `\x15\x03\x01\x00\x02\x02` indicates an HTTP response from your proxy, not HTTPS. Make sure your proxy is properly configured for HTTPS. – anothermh Feb 11 '20 at 18:07

0 Answers0