zoukankan      html  css  js  c++  java
  • ruby的json请求

    require 'net/http'
    require 'uri'
    require 'json'

    customers = [{
        "id" => 1123,
        "name" => "B-abc",
        "citys" => "",
        "company" => "",
        "siteUrl" => "www.abc.com",
        "domain" => "www.abc.com",
        "contact" => "张三",
        "phone" => "12222222",
        "mobilePhone" => "",
        "mail" => "",
        "status" => 1
    }].to_json

    def send_data(url,data)
        url = URI.parse(url)
        req = Net::HTTP::Post.new(url.path,{'Content-Type' => 'application/json'})
        req.body = data
        res = Net::HTTP.new(url.host,url.port).start{|http| http.request(req)}

        puts res.body                                                                                                
    end

  • 相关阅读:
    关于运行和调试的困惑
    初识函数
    Php的基本语法
    Apache的安装
    php的初步了解
    线程笔记
    Matlab笔记
    matlab取模与取余
    DialogFragment学习笔记
    MVP学习笔记——参考Google官方demo
  • 原文地址:https://www.cnblogs.com/zhangfei/p/3140729.html
Copyright © 2011-2022 走看看