doulongti5932 2014-11-22 04:56
浏览 59
已采纳

在Go中请求URL

I like to ask, if how can i run URL using go. I have ruby code that i like to convert to Go.

url4 = "https://rest.nexmo.com/sms/xml?api_key=KEY&api_secret=SECRET&from=Aphelion&to=#{params[:user][:mobile_num]}&text=Test SMS"
encoded_url3 = URI.encode(url4)
url5= URI.parse(encoded_url3)
req3 = Net::HTTP::Get.new(url5.to_s)
res = Net::HTTP.start('rest.nexmo.com', 80) {|http|
  http.request(req3)
}

Thank you

  • 写回答

1条回答 默认 最新

  • dsk88199 2014-11-22 06:00
    关注

    The standard net/http package provides a default http client for performing http requests.

    package main
    
    import (
            "fmt"
            "io/ioutil"
            "net/http"
    )
    
    func main() {
            resp, err := http.Get("https://rest.nexmo.com/sms/xml")
            if err != nil {
                    panic(err)
            }
            defer resp.Body.Close()
            body, err := ioutil.ReadAll(resp.Body)
            if err != nil {
                    panic(err)
            }
            fmt.Printf("%s", body)
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装