我坚持使用 Golang 执行 get 请求,我也尝试了三种不同的实现,但均未成功。对于所有这些,我都收到此错误消息:
获取 https://11.11.11.1:0000/httpgw.conf?Type=SMS&Address=12345678&MsgID=12 3&Notify=N&Validity=24:00&OAdC=15555&Message=HelloBrother: tls: 超大记录 d 收到长度为 20527
下面是我正在处理的完整源代码:
package main
import (
"crypto/tls"
"fmt"
"io/ioutil"
"net/http"
"os"
)
func main() {
cmdSecSMS := "https://11.11.11.1:0000/httpgw.conf?Type=SMS&Address=12345678&MsgID=123&Notify=N&Validity=24:00&OAdC=15555&Message="
msg := "HelloBrother"
cmdSecUrlSMS := cmdSecSMS + msg
doClientTrans(cmdSecUrlSMS)
doGetClient(cmdSecUrlSMS)
doGet(cmdSecUrlSMS)
}
func doClientTrans(address string) {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client := &http.Client{Transport: tr}
response, err := client.Get(address)
if err != nil {
fmt.Printf("%s", err)
os.Exit(1)
} else {
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
fmt.Printf("%s", err)
os.Exit(1)
}
fmt.Printf("%s\n", string(contents))
fmt.Println(" Size: ", len(string(contents)), " url: ", address)
fmt.Println(" Status Code: ", response.StatusCode)
hdr := response.Header
for key, value := range hdr {
fmt.Println(" ", key, ":", value)
}
}
}
func doGet(url string) {
response, err := http.Get(url)
if err != nil {
fmt.Printf("%s", err)
os.Exit(1)
} else {
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
fmt.Printf("%s", err)
os.Exit(1)
}
fmt.Println(" Size: ", len(string(contents)), " url: ", url)
fmt.Println(" Status Code: ", response.StatusCode)
hdr := response.Header
for key, value := range hdr {
fmt.Println(" ", key, ":", value)
}
}
}
func doGetClient(url string) {
client := &http.Client{}
response, err := client.Get(url)
if err != nil {
fmt.Printf("%s", err)
os.Exit(1)
} else {
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
fmt.Printf("%s", err)
os.Exit(1)
}
fmt.Println(" Size: ", len(string(contents)), " url: ", url)
fmt.Println(" Status Code: ", response.StatusCode)
hdr := response.Header
for key, value := range hdr {
fmt.Println(" ", key, ":", value)
}
}
}
使用telnet时,这个GET请求正常:
远程登录 11.11.11.1 0000
获取https://11.11.11.1:0000/httpgw.conf?Type=SMS&Address=12345678&MsgID=12 3&Notify=N&Validity=24:00&OAdC=15555&Message=HelloBrother HTTP/1.1
^: 退出
我在 Windows Server 2012 中运行 golang 应用程序,我对服务器技术堆栈一无所知。
有可能解决这个问题吗?有配置解决方法或其他我可以尝试的方法吗?
谢谢你的帮助
最佳答案
我很高兴与您分享我实现了所需的实现。
下面的代码有效!
感谢您的意见,它们指导我以正确的方法完成这项任务:
package main
import (
"bufio"
"crypto/tls"
"fmt"
"io/ioutil"
"net"
"net/http"
"os"
)
func main() {
cmdSecSMS := "GET https://10.xxx.xx.x:xx43/httpgw.conf?" +
"Type=SMS&Address=5511111&MsgID=123&Notify=N&Validity=24:00&OAdC=15555&" +
"Message=blablah " +
"HTTP/1.1"
fmt.Println(cmdSecSMS)
cmdSecUrlSMS := cmdSecSMS
hostName := "10.xxx.xx.x"
portNum := "xx43"
doDial(cmdSecUrlSMS, hostName, portNum)
//doClientTrans(cmdSecUrlSMS)
//doGetClient(cmdSecUrlSMS)
//doGet(cmdSecUrlSMS)
}
func doDial(cmd, host, port string) {
// connect to this socket
conn, err := net.Dial("tcp", host+":"+port)
if err != nil {
fmt.Printf("Some error %v", err)
return
} else {
defer conn.Close()
fmt.Printf("Connection established between %s and localhost.\n", host)
fmt.Printf("Local Address : %s \n", conn.LocalAddr().String())
fmt.Printf("Remote Address : %s \n", conn.RemoteAddr().String())
// send to socket
fmt.Fprintf(conn, cmd+"\n")
// listen for reply
message, _ := bufio.NewReader(conn).ReadString('\n')
fmt.Print("Message from server: " + message)
}
谢谢大家的支持!
关于networking - net/http GET 请求错误 tls 收到长度为 20527 的超大记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34678564/
作为我的Rails应用程序的一部分,我编写了一个小导入程序,它从我们的LDAP系统中吸取数据并将其塞入一个用户表中。不幸的是,与LDAP相关的代码在遍历我们的32K用户时泄漏了大量内存,我一直无法弄清楚如何解决这个问题。这个问题似乎在某种程度上与LDAP库有关,因为当我删除对LDAP内容的调用时,内存使用情况会很好地稳定下来。此外,不断增加的对象是Net::BER::BerIdentifiedString和Net::BER::BerIdentifiedArray,它们都是LDAP库的一部分。当我运行导入时,内存使用量最终达到超过1GB的峰值。如果问题存在,我需要找到一些方法来更正我的代
是的,我知道最好使用webmock,但我想知道如何在RSpec中模拟此方法:defmethod_to_testurl=URI.parseurireq=Net::HTTP::Post.newurl.pathres=Net::HTTP.start(url.host,url.port)do|http|http.requestreq,foo:1endresend这是RSpec:let(:uri){'http://example.com'}specify'HTTPcall'dohttp=mock:httpNet::HTTP.stub!(:start).and_yieldhttphttp.shou
在我的Controller中,我通过以下方式在我的index方法中支持HTML和JSON:respond_todo|format|format.htmlformat.json{renderjson:@user}end在浏览器中拉起它时,它会自然地以HTML呈现。但是,当我对/user资源进行内容类型为application/json的curl调用时(因为它是索引方法),我仍然将HTML作为响应。如何获取JSON作为响应?我还需要说明什么? 最佳答案 您应该将.json附加到请求的url,提供的格式在routes.rb的路径中定义。这
Sinatra新手;我正在运行一些rspec测试,但在日志中收到了一堆不需要的噪音。如何消除日志中过多的噪音?我仔细检查了环境是否设置为:test,这意味着记录器级别应设置为WARN而不是DEBUG。spec_helper:require"./app"require"sinatra"require"rspec"require"rack/test"require"database_cleaner"require"factory_girl"set:environment,:testFactoryGirl.definition_file_paths=%w{./factories./test/
我有两个Rails模型,即Invoice和Invoice_details。一个Invoice_details属于Invoice,一个Invoice有多个Invoice_details。我无法使用accepts_nested_attributes_forinInvoice通过Invoice模型保存Invoice_details。我收到以下错误:(0.2ms)BEGIN(0.2ms)ROLLBACKCompleted422UnprocessableEntityin25ms(ActiveRecord:4.0ms)ActiveRecord::RecordInvalid(Validationfa
rails中是否有任何规定允许站点的所有AJAXPOST请求在没有authenticity_token的情况下通过?我有一个调用Controller方法的JqueryPOSTajax调用,但我没有在其中放置任何真实性代码,但调用成功。我的ApplicationController确实有'request_forgery_protection'并且我已经改变了config.action_controller.consider_all_requests_local在我的environments/development.rb中为false我还搜索了我的代码以确保我没有重载ajaxSend来发送
我目前正在使用以下方法获取页面的源代码:Net::HTTP.get(URI.parse(page.url))我还想获取HTTP状态,而无需发出第二个请求。有没有办法用另一种方法做到这一点?我一直在查看文档,但似乎找不到我要找的东西。 最佳答案 在我看来,除非您需要一些真正的低级访问或控制,否则最好使用Ruby的内置Open::URI模块:require'open-uri'io=open('http://www.example.org/')#=>#body=io.read[0,50]#=>"["200","OK"]io.base_ur
简而言之错误:NOTE:Gem::SourceIndex#add_specisdeprecated,useSpecification.add_spec.Itwillberemovedonorafter2011-11-01.Gem::SourceIndex#add_speccalledfrom/opt/local/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:91./opt/local/lib/ruby/gems/1.8/gems/rails-2.3.8/lib/rails/gem_dependency.rb:275:in`==':und
有人知道在发布新版本的Ruby和Rails时收到电子邮件的方法吗?他们有邮件列表,RubyonRails有一个推特,但我不想听到那些随之而来的喧嚣,我只想知道什么时候发布新版本,尤其是那些有安全修复的版本。 最佳答案 从therailsblog获取提要.http://weblog.rubyonrails.org/feed/atom.xml 关于ruby-on-rails-如何在发布新的Ruby或Rails版本时收到通知?,我们在StackOverflow上找到一个类似的问题:
1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里