2015-10-20 00:46

网络/ 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(""). 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.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • dongzhanbi0027 dongzhanbi0027 6年前

    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.


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


    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.

    点赞 评论 复制链接分享