4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

rubyでproxy、ssl、基本認証のサイトへポスト

Last updated at Posted at 2014-12-15

Webサイト閲覧にproxyが必要で、httpsのサイトへポストしたい。
かつ、基本認証がかかってる場合のrubyでのやり方。

参考
http://shirusu-ni-tarazu.hatenablog.jp/entry/2012/07/02/023326
http://qiita.com/bokuo-okubo/items/60f74243a26a23621894

require 'net/http'
require 'openssl'

#proxyサーバ
proxy = 'proxy.co.jp'

#POST先パス
req = Net::HTTP::Post.new('/post_path')
#基本認証のID, PASS
req.basic_auth 'id', 'password'
#ポストするパラメータ
req.set_form_data(key: post_data)

#proxyを設定
http = Net::HTTP::Proxy(proxy, 8080)
#SSLサイトを設定
http = http.new('https_site_host.co.jp', 443)
#sslを使う
http.use_ssl = true
#証明書は使わない
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
#リクエスト送信
http.request(req)
4
5
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?