doufei16736 2015-10-20 00:46
浏览 28
已采纳

网络/ Golang-剖析“ GET”请求

I imagine this is something that has been asked before, and answered, but I have no idea what to search to find it. This occurs to me as something that you would learn as part of a college course on computer networking - something I never took. If someone can point me towards the answer, that would be great.

So, the question is:

In many languages, like Go and JavaScript, it is relatively simple to make a "GET" request to an API over http/https. But what is happening under the surface, in a relatively high-level description?

I ask because I need a better understanding to grasp how to handle various errors that I receive when things don't behave as they should.

For an idea of the kind of answer I'm going for, I'll refer to the Golang method of making http calls. In Golang, you can import the net/http package and make the call as such http.Get("http://www.example.com"). But you can also specify a "client" which you can configure to have things like specific customized headers, etc. You can specify some more complex things inside the client like the transport used, and more, stuff that I'm not really interested in unless it solves my problem.

Basically, it comes down to this: Go is completely concurrent, and in my case parallel. I'm making around 300 requests every second to one API. The suggestion from the golang docs is that clients are safe for concurrent use, so should only instantiated once - essentially, I have one global client through which flows every request.

If I get an error saying that a connection has been killed, does that affect one request, many requests, do I have to do anything to the client to get another connection?

Also, is it one request per connection at a time, or is there a new connection made for every request? Are connections persistent between requests, what determines when they die?

This question is probably pretty rambling, and may not make sense. If anyone can answer any section of it, that would greatly be appreciated.

  • 写回答

1条回答 默认 最新

  • dongzhanbi0027 2015-10-20 01:36
    关注

    the network:

    dns->ip->tcp->http. DNS resolve the domain to a ip address; tcp adding a port (like HTTP default 80) and others; http adding headers, form data and others. finally your http load in ip packet send from your network adapter and well processed by routers in Internet and will arrive to right http server.

    net/http:

    we have answer to all your transport layer questions in golang document, mainly this. please read it carefully.

    update:

    a connection error just effect one request. even if multiple request use same tcp connection, because the request-reponse pair goes one bye one, so one connection error will never make two request fail.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型