net-http

Ruby Proxy Authentication GET/POST with OpenURI or net/http

天涯浪子 提交于 2019-12-05 07:22:09
I'm using ruby 1.9.3 and trying to use open-uri to get a url and try posting using Net:HTTP Im trying to use proxy authentication for both: Trying to do a POST request with net/http : require 'net/http' require 'open-uri' http = Net::HTTP.new("google.com", 80) headers = { 'User-Agent' => 'Ruby 193'} resp, data = http.post("/", "name1=value1&name2=value2", headers) puts data And for open-uri which I can't get to do POST I use: data = open("http://google.com/","User-Agent"=> "Ruby 193").read How would I modify these to use a proxy with HTTP Authentication I've tried (for open-uri) data = open(

How to scrape a website with the socksify gem (proxy)

ぃ、小莉子 提交于 2019-12-05 06:45:52
问题 I am reading through the documentation of the socksify gem on Rubyforge. I have installed the gem successfully, and I have run this documented code with success to test that my local implementation can replicate it: require 'socksify/http' uri = URI.parse('http://rubyforge.org/') Net::HTTP.SOCKSProxy('127.0.0.1', 9050).start(uri.host, uri.port) do |http| http.get(uri.path) end # => #<Net::HTTPOK 200 OK readbody=true> But how do I e.g. scrape 'http://google.com/' , and get the html content? I

Ruby Mechanize, Nokogiri and Net::HTTP

南笙酒味 提交于 2019-12-04 14:58:02
I am using Net::HTTP for HTTP requests and getting a response back: uri = URI("http://www.example.com") http = Net::HTTP.start(uri.host, uri.port, proxy_host, proxy_port) request = Net::HTTP::Get.new uri.request_uri response = http.request request # Net::HTTPResponse object body = response.body If I have to use the Nokogiri gem in order to parse this HTML response I will do: nokogiri_obj = Nokogiri::HTML(body) But if I want to use Mechanize gem I need to do this: agent = Mechanize.new mechanize_obj = agent.get("http://www.example.com") Is it possible for me to use Net::Http for getting the

Why do I get Net::HTTP “request path is empty” error?

こ雲淡風輕ζ 提交于 2019-12-04 14:39:33
I'm using Net::HTTP to make a HTTP request. I get the error "HTTP request path is empty", but I strongly feel that it is not. The code is below: REQUEST_IP = "localhost" REQUEST_PORT = "8081" REQUEST_PATH = "myweb/rest" def customServiceMailAndMessageRequest user_id, message url = 'http://' + REQUEST_IP + ":" + REQUEST_PORT + "/" + REQUEST_PATH + '/users/' + user_id + '/messages/sendMailAndMessage?message=' + message uri = URI(url) request = Net::HTTP::Get.new(uri.path) request['Content-Type'] = 'application/json' request['Accept'] = 'application/json' response = Net::HTTP.new(uri.host,uri

Posting Ruby data in JSON format with Net/http

こ雲淡風輕ζ 提交于 2019-12-04 13:13:04
I have this ruby file: require 'net/http' require 'json' require 'uri' #test data newAcctJson ='{ "type": "Credit Card", "nickname": "MoreTesting", "rewards": 2, "balance": 50 }' #creates a new account def createAcct(custID, json) url = "http://api.reimaginebanking.com:80/customers/#{custID}/accounts?key=#{APIkey}" uri = URI.parse(url) http = Net::HTTP.new(uri.host, uri.port) myHash = JSON.parse(json) resp = Net::HTTP.post_form(uri, myHash) puts(resp.body) end which attempts to create a new account. However I get code: 400, invalid fields in account . I tested the data independently, so I'm

How to scrape a website with the socksify gem (proxy)

不想你离开。 提交于 2019-12-03 22:11:43
I am reading through the documentation of the socksify gem on Rubyforge. I have installed the gem successfully, and I have run this documented code with success to test that my local implementation can replicate it: require 'socksify/http' uri = URI.parse('http://rubyforge.org/') Net::HTTP.SOCKSProxy('127.0.0.1', 9050).start(uri.host, uri.port) do |http| http.get(uri.path) end # => #<Net::HTTPOK 200 OK readbody=true> But how do I e.g. scrape 'http://google.com/' , and get the html content? I wish to parse it with e.g. Nokogiri like this: Nokogiri::HTML(open("http://google.com/)) require

Ruby, Tor and Net::HTTP::Proxy

断了今生、忘了曾经 提交于 2019-12-03 10:10:19
问题 My apologies in advance if this is a noobish doubt: I want to use a proxy in my Ruby code to fetch a few web pages. And I want to be sneaky about it! So I am using Tor. I have Tor running, and I am able to use Net::HTTP.get(uri) as usual. But I can't figure out how to use Net::HTTP::Proxy to fetch the uri. I also can't figure out how using Tor will help make my fetches anonymous. Any help is greatly appreciated. Please don't just add a link to the ruby-doc page for Net::HTTP::Proxy. If I had

Sending a Post request with net/http

∥☆過路亽.° 提交于 2019-12-03 08:42:38
问题 I need to send data in JSON to another app which runs on the same computer. I send request like so (rails 3.2.13 ) data = { //some data hash } url = URI.parse('http://localhost:6379/api/plans') resp, data = Net::HTTP.post_form(url, data.to_JSON ) p resp p data { resp: resp, data: data.to_JSON } But i get Net::HTTPBadResponse (wrong status line: "-ERR unknown command 'POST'"): How can i solve this problem? Update 1 Updated my code as @Raja-d suggested url = URI.parse('http://localhost:6379/v1

Sending a Post request with net/http

人盡茶涼 提交于 2019-12-03 00:13:22
I need to send data in JSON to another app which runs on the same computer. I send request like so (rails 3.2.13 ) data = { //some data hash } url = URI.parse('http://localhost:6379/api/plans') resp, data = Net::HTTP.post_form(url, data.to_JSON ) p resp p data { resp: resp, data: data.to_JSON } But i get Net::HTTPBadResponse (wrong status line: "-ERR unknown command 'POST'"): How can i solve this problem? Update 1 Updated my code as @Raja-d suggested url = URI.parse('http://localhost:6379/v1/sessions') http = Net::HTTP.new(url.host, url.port) http.use_ssl = true resp, data = Net::HTTP.post

Escaping parameters in set_form_data POST

南楼画角 提交于 2019-12-02 23:22:33
问题 This is the oddest thing. When I add the ; in set_form_data , value gets interpreted as value; on the server side. When I remove the ; , the value for 'dontescape' gets interpreted as file%3a%2f%2f%2fpath%2fto . What the heck is happening? I don't want anything escaped unless I explicitly call CGI::escape! Please help :) postParams = { 'key1' => 'value', 'dontescape' => 'file:///path/to' } url = URI.parse('https://my.url') req = Net::HTTP::Post.new(url.path) req.basic_auth('username',