Android programming uses HTTP protocol and TCP protocol to upload files

This paper describes the method of uploading files using HTTP protocol and TCP protocol in Android programming. Share with you for your reference, as follows:

There are two ways for Android to upload files. The first is httpurlconnection based on HTTP protocol, and the second is socket based on TCP protocol. The difference between the two methods is that there is an internal cache mechanism when uploading using httpurlconnection. If a large file is uploaded, it will lead to memory overflow. If you upload using TCP socket, this disadvantage will be solved.

HTTP protocol httpurlconnection

1. Open an httpurlconnection through the URL encapsulation path 2. Set the request method and header fields: content type, content length and host 3. Send splicing data

Example:

TCP protocol socket

1. We can use socket to send TCP requests and send uploaded data in segments

Example:

Build a server to complete the upload function

I hope this article will help you in Android programming.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>