How could we fool the HTTP protocol?

谁都会走 提交于 2019-12-19 04:46:49

问题


Although HTTP is ubiquitous it comes with its baggage of Headers which in my case is becoming more of a problem. My data to be transferred is an iota of the HTTP header size.

  • Is there another protocol that I can use which is still understood by the browsers and other networks and doesn't come with the baggage of HTTP?
  • Any other way to skip headers and add it at the destination so only a miniscule of data is transferred over the network?

回答1:


  1. No.
  2. No.

Many HTTP headers are optional. A typical browser request is much larger than a minimal request, which might look like:

GET /doc HTTP/1.1
Host: example.com
Connection: close

(I can say with confidence that requests of this form work because I use them all the time when testing Web server response via telnet example.com 80.)

Possibly you can get useful results simply by omitting some headers.




回答2:


HTTP requests can be quite small. As chaos points out in his answer, you don't really need to send many headers with a request. The only header that's essential is Host. I can simplify chaos' example a bit more by using HTTP 1.0, which doesn't feature persistent connections.

GET / HTTP/1.0
Host: example.com
                                       (blank line is necessary)

The reply can be similarly simple

HTTP/1.0 200 OK
Content-Type: text/html

data content

In this case, the overhead of HTTP is about 40 bytes in the request and the response. A standard TCP packet is 1500 bytes so you have plenty of room left over in the response packet for the actual data.

There are other HTTP headers, and they do have value. You can include cache information and do conditional GETs. You can use an HTTP/1.1 persistent socket to make subsequent requests faster. Etc, etc. You don't have to use any of this stuff if you don't want, but one nice thing about HTTP is there's a standard way to do more complicated protocols when you need it.

As for doing minimal HTTP in JavaME, if you really care about every byte you may be best off writing your own simple HTTP client by working with a plain TCP socket. If you're talking to a known server you don't need to implement much at all. (If you're talking to arbitrary servers, you need to pay more attention to error handling, redirects, etc).




回答3:


WebSockets are coming in HTML5 and should suit your needs. A standard HTTP connection can be renegotiated to change protocol to websockets. But I suspect the specification might be a bit young, but it might fit the bill.



来源:https://stackoverflow.com/questions/1449096/how-could-we-fool-the-http-protocol

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!