class Nastika::HTTP::Post
Crafting POST requests
Attributes
forminf[RW]
headers[RW]
httpver[RW]
reqpath[RW]
Public Class Methods
new(reqpath=Nastika::Constants::DEFAULT_REQPATH, httpver=Nastika::Constants::DEFAULT_HTTPVER, headers=Nastika::Constants::DEFAULT_HEADERS, forminf=Nastika::Constants::DEFAULT_FORMINF)
click to toggle source
Initializes the object Params:
reqpath
-
the path to request
httpver
-
the
HTTP
version to use headers
-
Additional headers to use
forminf
-
Form information
# File lib/nastika/http_post_request.rb, line 18 def initialize(reqpath=Nastika::Constants::DEFAULT_REQPATH, httpver=Nastika::Constants::DEFAULT_HTTPVER, headers=Nastika::Constants::DEFAULT_HEADERS, forminf=Nastika::Constants::DEFAULT_FORMINF) self.reqpath = reqpath self.headers = headers self.httpver = httpver self.forminf = forminf end
Public Instance Methods
to_s()
click to toggle source
Convert the object to a string
# File lib/nastika/http_post_request.rb, line 29 def to_s payload = "" payload += "POST #{self.reqpath} HTTP/#{self.httpver}\r\n" self.headers.each do |key, val| payload += "#{key}: #{val}\r\n" end self.forminf.each_with_index do |(key, val), i| payload += "#{key}=#{val}" payload += "&" unless i == forminf.length-1 end payload += "\r\n\r\n" return payload end