对HTTP协议感到困惑

发布于 2024-12-08 15:48:43 字数 251 浏览 0 评论 0原文

我对 HTTP 协议有点困惑,据我所知,HTTP 是为了传递网页而创建的,主要是在 Web 服务器和浏览器之间发送消息。 但似乎许多应用程序都使用了 HTTP,这些应用程序确实使用互联网进行通信,但不是 Web 应用程序(“使用 Web 浏览器作为客户端的应用程序”)。

我问这个问题是因为我开始开发 iPhone 应用程序(一种导航应用程序),并且我需要在 iPhone 客户端和我的服务器之间发送消息。现在人们一直告诉我使用 HTTP 协议,但这真的是正确的方法吗?

I'm a little confused about the HTTP protocol, from what i know HTTP was made for delivering web pages and primarily sending messages between a web server and a browser.
But it seems that HTTP is used anywhere in a lot of apps that indeed uses the internet for communicating but are not web application("application that uses a web browser as a client").

I'm asking this because i started developing an iPhone app (kind of navigation app) and i need to send messages between the iPhone client and my server. Now people keep telling me to use HTTP protocol, but is this really the way to go?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

蹲在坟头点根烟 2024-12-15 15:48:44

同意从 SOAP 转向 REST 和 QUERY 是一件好事。
我们目前正在实现一个使用 HTTP 作为双向传输机制的系统。
上传到服务器的响应是标准 HTTP 响应,例如 200 = 成功但没有正文。
对查询的响应是一个 ASCII 文本页,其中答案作为正文。然后我们只需将 ASCII 转换回二进制即可使用数据。
这种方法的优点是你只需要提供正确的 URL 和参数就可以处理一切。
除非您的协议栈知道如何格式化 post 和 get 请求,否则您将需要自己执行此操作。虽然这很乏味,但它在 W3C 协议 中有详细记录,但它有点必须自己经历这一切,这很乏味。因此,如果您必须这样做,那么我建议您购买一本电子书来帮助理清细节。一些例子是:
HTTP

Agreed that the move to REST and QUERY from SOAP is a good thing.
We are currently implementing a system that will use HTTP as the bidirectional transfer mechanism.
The response back to uploads to the server is a standard HTTP response such as 200 = success with no body.
The response to a query is an ASCII text page with the answer as the body. We then just turn the ASCII back to binary to use the data.
The advantage of this method is that you just have to provide the right URL and parameters and you can handle everything.
Unless your protocol stack knows how to format post and get requests, then you will need to do that yourself. While this is tedious it is well documented at W3C Protocols however it is a bit tedious to have to go through it all yourself. So if you are having to fo that then I recommend getting an eBook to help sort out the details. Some examples are:
HTTP

灯角 2024-12-15 15:48:44

https 代表超文本传输​​文本,它有助于客户端与服务器进行通信。客户端称为发出请求的设备,服务器称为处理该请求,有四种方法。例如,当您进入某个网站时,您的浏览器将发出请求以获取 html、css、js 和其他文件,以及图像(如果需要)(GET 方法)。您可以在很多网站表单中看到另一个例子,您需要填写该表单才能进入系统,它被称为(POST 方法)。此外,如果您在 Facebook 上有一篇帖子,并且您想要重写或编辑该帖子,则称为(PUT 方法),您将仅更改一项内容,而不会触及另一项内容。最后一个是(DELETE 方法),当你想删除 facebook 中的某些内容时使用它

https stands for Hyper Text Transfer Text, it helps communicate a client with the server. The client is called a device being made request, server is called handling that request, there four methods. For example when you get into some website your browser will make request in order to get html, css, js and other file, and also images if they need (GET method). Another example you can see in a lot of website form which you need to fill to get into system it is called (POST method). Also if you have a post for example in facebook, and you want to rewrite or edit this post it is called (PUT method), you will change only one content without touching another one. And the last one is (DELETE method), it is used when you want delete something in facebook

暮光沉寂 2024-12-15 15:48:43

你的问题是有效的,如果我可以重申一下,为什么我们对每个服务器客户端通信都使用 HTTP,而它通常用于浏览器 Web 服务器用例,并且与直接 TCP 通信相比效率较低。我的理由如下:

  • HTTP 协议非常简单,就像技术中的许多事情一样,即使复杂的解决方案更有效(除非有很大的优势),简单性胜过复杂性。
  • HTTP 协议是无状态的,这使得通过添加更多机器来水平扩展变得更加简单,并通过简单的负载平衡技术(如循环)来平衡负载。
  • 很容易找到一个合理且免费的 HTTP 服务器来让您的应用程序尽快启动并运行,而不是实现您自己的协议、服务器,并将您的注意力从您想要解决的实际问题上移开。
  • 与多方使用的任何简单技术一样,它会随着时间的推移而变得更好,并且通过诸如 Keep-Alive、分块传输、管道传输等现代功能,您可以克服连接开销的一些缺点。

Your question is valid, if I can restate, why are we using HTTP for every Server-Client communications while it was meant typically for browser-web server use case and can be less efficient compared to direct TCP communication. My reasons below :

  • HTTP protocol is extremely simple and like many things in tech simplicity trumps complexity even if the complex solution is more efficient (unless by a huge margin).
  • HTTP protocol is stateless making it much simpler to scale horizontally by adding more machines and balance load by simple load balancing techniques like round robin.
  • Easy to find a reasonable and free HTTP server to get your app up and running soon than implementing your own protocols, servers and taking your focus away from the real problem you want to solve.
  • Like any simple technology used by many parties, it gets better with time and with modern features like Keep-Alive, chunked transfer, pipelining you can overcome some drawbacks of connections overheads.
始于初秋 2024-12-15 15:48:43

是的,这就是要走的路。您还想怎样做呢?

Web Server <-------HTTP-------> Client

客户端可以是浏览器、手机、Xbox。服务器请求接收端的任何东西都是客户端。

Yes that's the way to go. How else do you want to go about it?

Web Server <-------HTTP-------> Client

Client can be a browser, a mobile phone, an xbox. Anything on the receiving end of a server request is a client.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文