Skip to content

Instantly share code, notes, and snippets.

@yaoyi
Created August 21, 2013 03:25
Show Gist options
  • Save yaoyi/6290040 to your computer and use it in GitHub Desktop.
Save yaoyi/6290040 to your computer and use it in GitHub Desktop.
require "net/http"
require "uri"
require 'json'
# http://checkcosmetic.net
# uri = URI.parse("http://checkcosmetic.net/wp-admin/admin-ajax.php")
# http://cosmetic.momoko.hk
uri = URI.parse("http://cosmetic.momoko.hk/calculate.php")
request = Net::HTTP::Post.new(uri.path)
# http://checkcosmetic.net
# request.set_form_data({
# 'action' => 'dc_checkAJAX',
# 'code' => 0303,
# 'brand'=>'12839',
# 'brandid' => 'c4fb753df6b386d98ead81f30a0bbed0'})
# http://cosmetic.momoko.hk
request.set_form_data({
'brand' => 'C6',
'code' => 6403})
request["User-Agent"] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36"
request["Accept"] = "*/*"
request["Content-type"] = "application/x-www-form-urlencoded"
request["Referer"] = "http://cosmetic.momoko.hk/"
request["Connection"] = "keep-alive"
request["X-Requested-With"] = "XMLHttpRequest"
request["Host"] = "cosmetic.momoko.hk"
request["Origin"] = "http://cosmetic.momoko.hk"
request["Accept-Language"] = "zh-CN,zh;q=0.8"
response = Net::HTTP.start(uri.hostname, uri.port) do |http|
http.request(request)
end
case response
when Net::HTTPSuccess
p 'hello'
# response["content-type"]
# response.each_header do |key, value|
# p "#{key} => #{value}"
# end
result = JSON.parse(response.body)
p result['title']
p result['date']
else
p response.value
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment