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 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测