net-http

Connect to Microsoft Azure Machine Learning Studio Api with ruby instead of python use net/http gem instead of urllib2

断了今生、忘了曾经 提交于 2019-12-12 02:39:05
问题 I need to connect to the Microsoft Azure Machine Learning Studio Api with ruby instead of python. Can someone help me translate this python code into ruby using the net/http gem. import urllib2 # If you are using Python 3+, import urllib instead of urllib2 import json data = { "Id": "score00001", "Instance": { "FeatureVector": { "value_1"= "1", "value_2"= "2", "value_3"= "3", "value_4"= "4", "value_5"= "5", "value_6"= "6", "value_7"= "7", "value_8"= "8", "value_9"= "9", "value_10"= "10", },

Net HTTP unescapes characters?

折月煮酒 提交于 2019-12-11 08:45:58
问题 Does Ruby Net HTTP unescape characters (for example 龅 to 龅 )? I send a request using HTTParty with 龅 but the request parameters on the request server show 龅 instead. 回答1: Net::HTTP doesn't do any conversion or decoding. It's just a pipe to move data. If you are seeing converted characters on the server side then something there is changing them before you can see them. This shows what Net::HTTP is sending. In test.rb: #!/usr/bin/env ruby require 'ap' require 'sinatra' post '/' do t = %w[text

Using Ruby on Rails to POST JSON/XML data to a web service

我的梦境 提交于 2019-12-11 07:43:50
问题 I built a web service in using Spring framework in Java and have it run on a tc server on localhost. I tested the web service using curl and it works. In other words, this curl command will post a new transaction to the web service. curl -X POST -H 'Accept:application/json' -H 'Content-Type: application/json' http://localhost:8080/BarcodePayment/transactions/ --data '{"id":5,"amount":5.0,"paid":true}' Now, I am building a web app using RoR and would like to do something similar. How can I

Ruby SSL handshake not receiving Server Hello back - using proxy Net::HTTP

守給你的承諾、 提交于 2019-12-11 06:25:43
问题 I am connecting to an external API using Ruby SSL two way authentication. My latest script is here: namespace :rnif_message do # With Proxy task send_test_index: :environment do our_cert = File.read(File.join(Rails.root, 'ssl', 'invoice', 'test', 'cert20190116_ourcert.der')) their_test_cert = File.read(File.join(Rails.root, 'ssl', 'invoice', 'test', 'testcert2016_theircert.der')) cert_store = OpenSSL::X509::Store.new # Contains their intermediate CA files cert_store.add_path File.join(Rails

Ruby 2.3 - Adding Timeout error and notification to net:http request

你说的曾经没有我的故事 提交于 2019-12-11 06:17:02
问题 I have a working system to produce errors and send them to be used by Active Admin. For example in Active admin, for a specific page of our CMS, the page might execute : url_must_be_accessible("http://www.exmaple.com", field_url_partner, "URL for the partner") And this uses the code below to send to the Active Admin Editor different type of errors notifications: module UrlHttpResponseHelper def url_must_be_accessible(url, target_field, field_name) if url url_response_code = get_url_http

In RoR, how do I recover from a “Failed to open TCP connection … (general SOCKS server failure)” error?

送分小仙女□ 提交于 2019-12-11 05:55:21
问题 I’m using Rails 4.2.7. Currently Im’ requesting web pages through a SOCKS proxy like so begin ... res1 = Net::HTTP.SOCKSProxy('127.0.0.1', 50001).start(uri.host, uri.port) do |http| puts "launching #{uri}" resp = http.get(uri) status = resp.code content = resp.body content_type = resp['content-type'] content_encoding = resp['content-encoding'] end ... rescue OpenURI::HTTPError => ex ... rescue SocketError, Net::OpenTimeout, Zlib::BufError => e ... end and occasionally I will get the following

How do I catch the “Error during processing: buffer error” in Ruby when getting a web page?

China☆狼群 提交于 2019-12-10 23:45:43
问题 I’m using Rails 4.2.7 and this code to get a webpage through a SOCKS proxy … begin … res1 = Net::HTTP.SOCKSProxy('127.0.0.1', 50001).start(uri.host, uri.port) do |http| puts "launching #{uri}" resp = http.get(uri) status = resp.code content = resp.body content_type = resp['content-type'] content_encoding = resp['content-encoding'] end … rescue OpenURI::HTTPError => ex … rescue SocketError, Net::OpenTimeout => e … Occasionally, I get an error on the line “rest = http.get(uri)” Error during

Mechanize getting “Errno::ECONNRESET: Connection reset by peer - SSL_connect”

余生长醉 提交于 2019-12-10 18:34:07
问题 I'm unable to get Mechanize to load a page that used to work -- it's reliably failing with a Errno: ECONNRESET: Connection reset by peer - SSL_connect message. Any suggestions as to what I should try or details I should look at? (Please see "what I've tried" below...) Update 1 Taking a hint from a related S.O. post, I tried accessing the site directly with Net::HTTP . When I set http.ssl_version = :TLSv1 , I get a redirect rather than an error (as it should be). So my question becomes: how

Net::HTTP extremely slow responses for HTTPS requests

感情迁移 提交于 2019-12-10 13:55:12
问题 For some reason, on my development machine I'm getting very, very slow responses for HTTPS requests performed via Net::HTTP. I've tried RestClient and HTTParty and they both have the same issue. It seems to have sprung from nowhere. I've made these requests hundreds of times without issue, but today they are unbearably slow. pry(main)> puts Time.now; HTTParty.get('https://api.easypost.com/v2/addresses'); puts Time.now; 2015-04-29 08:07:08 -0500 2015-04-29 08:09:39 -0500 As you can see, the

Using Ruby to post an XML request to a webserver

若如初见. 提交于 2019-12-08 16:01:24
问题 I'm afraid I've not got much experience with posting documents (e.g. XML) over web-servers, so I apologise if my understanding of HTTP is lacking. I have a basic Mongrel web server set up in a ruby app on 127.0.0.1 port 2000 . (The server). I am running a separate Ruby app on the same computer. (The client). I need the client to POST an XML document to the server. I have tried using Net::HTTP to do this, but I can't find a clear example which tells me what I should do. I've had a go, but