0
0

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.

uri HTTP.net

0
Posted at
  • HTTPリクエストを送るには、url(ipアドレス), portでリクエスト送れる

require 'uri'
require 'net/http'


uri = URI("http://localhost:5000/createPost")
params = { body: "hello"}

uri.query = URI.encode_www_form(params)

# get アクセスの仕方

req = Net::HTTP.new uri.host, uri.port

result =  req.get('/posts')
puts result.body

# post クエリなどを渡す時

req = Net::HTTP.new uri.host, uri.port

result = req.post(uri.path, uri.query)
puts result.body


# uri も最高

uri = URI("http://localhost:5000/createPost")
p uri.host

p uri.port
p uri.path

params = { body: "hello"}

uri.query = URI.encode_www_form(params)
p uri.query

記事

0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?