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.