CN108600378B - File downloading method, device, terminal and storage medium - Google Patents

File downloading method, device, terminal and storage medium Download PDF

Info

Publication number
CN108600378B
CN108600378B CN201810396790.8A CN201810396790A CN108600378B CN 108600378 B CN108600378 B CN 108600378B CN 201810396790 A CN201810396790 A CN 201810396790A CN 108600378 B CN108600378 B CN 108600378B
Authority
CN
China
Prior art keywords
target
file
request message
website
server
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201810396790.8A
Other languages
Chinese (zh)
Other versions
CN108600378A (en
Inventor
杨亮
张文明
陈少杰
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Wuhan Douyu Network Technology Co Ltd
Original Assignee
Wuhan Douyu Network Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Wuhan Douyu Network Technology Co Ltd filed Critical Wuhan Douyu Network Technology Co Ltd
Priority to CN201810396790.8A priority Critical patent/CN108600378B/en
Publication of CN108600378A publication Critical patent/CN108600378A/en
Application granted granted Critical
Publication of CN108600378B publication Critical patent/CN108600378B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/06Protocols specially adapted for file transfer, e.g. file transfer protocol [FTP]
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/02Protocols based on web technology, e.g. hypertext transfer protocol [HTTP]
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/14Session management
    • H04L67/148Migration or transfer of sessions

Abstract

The embodiment of the invention discloses a file downloading method, a file downloading device, a file downloading terminal and a storage medium. The method comprises the following steps: acquiring a target website corresponding to a file to be downloaded; generating a target request message according to a preset request method and a target website, and sending the target request message to a target server; determining a target response code according to the received target response message, wherein the target response message is sent by a target server according to a target request message; if the target response code is the transfer response code, determining a transfer website according to the target response message, updating a target request message according to the transfer website, and sending the updated target request message to a target server; and downloading the file to be downloaded according to the received updated target response message. The technical scheme of the embodiment of the invention can solve the problem that the redirected file cannot be automatically downloaded in the prior art, realizes the automatic downloading of the file, improves the downloading efficiency and improves the user experience.

Description

File downloading method, device, terminal and storage medium
Technical Field
The embodiment of the invention relates to network technology, in particular to a file downloading method, a file downloading device, a file downloading terminal and a storage medium.
Background
With the development of network technology, users often download required files in clients. Currently, downloading files in a server based on an HTTP (HyperText Transfer Protocol) network Protocol is one of the most common downloading methods.
However, when downloading the file data in a specific website, if the file data in the website is transferred to another path for some reason, the problem that the file data in the website cannot be downloaded is caused. In general, in the prior art, after a programmer finds that file data is transferred, namely website redirection occurs, jump downloading of a website is realized by manually writing related codes. Therefore, in the prior art, after the file is redirected, automatic downloading of file data cannot be realized, so that the downloading efficiency is reduced, and the user experience is influenced.
Disclosure of Invention
Embodiments of the present invention provide a file downloading method, apparatus, terminal and storage medium, so as to solve the problem in the prior art that the redirected file data cannot be automatically downloaded, and implement automatic downloading of a file, thereby improving downloading efficiency and improving user experience.
In a first aspect, an embodiment of the present invention provides a file downloading method, including:
acquiring a target website corresponding to a file to be downloaded;
generating a target request message according to a preset request method and the target website, and sending the target request message to a target server;
determining a target response code according to the received target response message, wherein the target response message is sent by the target server according to the target request message;
if the target response code is a transfer response code, determining a transfer website according to the target response message, updating the target request message according to the transfer website, and sending the updated target request message to the target server;
and downloading the file to be downloaded according to the received updated target response message.
In a second aspect, an embodiment of the present invention further provides a file downloading apparatus, including:
the target website acquisition module is used for acquiring a target website corresponding to the file to be downloaded;
the target request message generation module is used for generating a target request message according to a preset request method and the target website and sending the target request message to a target server;
a target response code determining module, configured to determine a target response code according to a received target response message, where the target response message is sent by the target server according to the target request message;
a target request message updating module, configured to determine a transfer website according to the target response message if the target response code is a transfer response code, update the target request message according to the transfer website, and send the updated target request message to the target server;
and the first file downloading module is used for downloading the file to be downloaded according to the received updated target response message.
In a third aspect, an embodiment of the present invention further provides a terminal, where the terminal includes:
one or more processors;
a memory for storing one or more programs;
when executed by the one or more processors, cause the one or more processors to implement a file download method as in any embodiment of the invention.
In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, where the computer program is executed by a processor to implement the file downloading method according to any embodiment of the present invention.
The embodiment of the invention generates a target request message according to a preset request method and a target website of a file to be downloaded, sends the target request message to a target server, and determines a target response code according to the received target response message; if the target response code is the transfer response code, determining a transfer website according to the target response message, updating the target request message according to the transfer website, and retransmitting the updated target request message to the target server to receive the updated target response message, so that the file to be downloaded is downloaded according to the updated target response message, when the website of the file to be downloaded is redirected, the file to be downloaded can be automatically downloaded according to the redirected transfer website, the problem that the redirected file cannot be automatically downloaded in the prior art is solved, the downloading efficiency is improved, and the user experience is improved.
Drawings
Fig. 1 is a flowchart of a file downloading method according to an embodiment of the present invention;
fig. 2 is a schematic structural diagram of a file downloading device according to a second embodiment of the present invention;
fig. 3 is a schematic structural diagram of a terminal according to a third embodiment of the present invention.
Detailed Description
The present invention will be described in further detail with reference to the accompanying drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting of the invention. It should be further noted that, for the convenience of description, only some of the structures related to the present invention are shown in the drawings, not all of the structures.
Example one
Fig. 1 is a flowchart of a file downloading method according to an embodiment of the present invention, which is applicable to a case where a file in a server is downloaded in a client. The method may be performed by a file downloading device, which may be implemented in software and/or hardware, integrated in a client. The method specifically comprises the following steps:
and S110, acquiring a target website corresponding to the file to be downloaded.
The file to be downloaded is an HTTP file which needs to be downloaded from a server by using an HTTP protocol. Each file to be downloaded corresponds to a target website. The target website in this embodiment refers to a URL (Uniform resource Locator) address based on the HTTP protocol. The target website corresponding to the file to be downloaded can be obtained by inputting the website by the user, or by directly clicking the website link corresponding to the file to be downloaded by the user. Illustratively, the name of the file to be downloaded is version.ini, where www indicates that the protocol of the file version.ini is the HTTP protocol, www.douyu.com indicates a host address, i.e., a domain name address, pcclient/version.ini indicates a resource path of the file to be downloaded, and it can be seen from the target website that the file to be downloaded is stored in the pcclient directory of www.douyu.com host.
And S120, generating a target request message according to the preset request method and the target website, and sending the target request message to a target server.
The request methods include, but are not limited to, GET, POST, OPTIONS, HEAD, PUT, DELETE, TRACE, and CONNECT. The preset request method can be preset according to actual conditions and requirements. Illustratively, the GET request method is typically employed when downloading HTTP files. The target request message may be an HTTP message requesting the target server to download a file. The target server in this embodiment refers to an HTTP server corresponding to the target website, and is configured to receive and respond to the target request packet sent by the file downloading apparatus.
Optionally, S120 includes:
determining a target IP address and a target port according to a target domain name address in a target website; based on the target IP address and the target port, connecting a target server by utilizing a socket and a read-write service object; and when the target server is successfully connected, generating a target request message according to the preset request method and the target website, and sending the target request message to the target server.
The HTTP Protocol is an upper layer application Protocol based on a TCP (Transmission Control Protocol) Protocol. Generally, the conventional TCP protocol requires a server to be connected according to an IP address and a port, so when a TCP connection is initiated, a target IP address and a target port, for example, an IP address of 127.0.0.1, must be provided. The target website based on the HTTP protocol only provides a domain name address, so that the target domain name address in the target website needs to be resolved, and a target IP address and a target port corresponding to the target domain name address are determined. Optionally, the hostntbyname is called to obtain a host structure, and the target IP address is analyzed according to the h _ addr _ list field in the host structure. Specifically, a target domain name address is transmitted to a gethostbyname function as a parameter through a gethostbyname network API (Application Programming Interface), so as to obtain a host structure data, and according to a h _ addr _ list field in the host structure, an inet _ ntoa is called to obtain h _ addr _ list [0], so that an IP address corresponding to the h _ addr _ list [0] is determined as a target IP address corresponding to the target domain name address. The default port of the HTTP server in this embodiment is 80, so that the target port can be directly determined to be 80. Illustratively, the target website address of the file version.ini to be downloaded is http:// www.douyu.com/pcclient/version.ini, and the target IP address corresponding to www.douyu.com is determined by passing the domain name address www.douyu.com as a parameter into the gethostbyname function. And according to the determined target IP address and the target port, transmitting TCP connection by utilizing a TCP SOCKET and an I/O read-write service object so as to connect the target server.
Optionally, based on the target IP address and the target port, connecting the target server by using the socket and the read-write service object includes:
establishing an asynchronous read-write service object; creating an asynchronous socket and transmitting a read-write service object into a construction function of the socket; calling a connection function of the socket, and transmitting a target IP address and a target port into the connection function; and determining whether the target server is successfully connected according to the parameter information in the first callback function, wherein the first callback function is used for receiving the connection result of the connection function.
In this embodiment, when the target server is connected, an ASIO (asynchronous IO) library of the boost open source library is used. Optionally, an asynchronous read-write service object with a type of boost:: asio:: io _ service is created through the new operator, and the read-write service object may be marked as m _ ioService. And establishing an asynchronous socket with the type of boost:: asio:: ip:: tcp:: socket through a new operational character, and transmitting the established m _ ioService read-write service object into the constructor of the type, wherein the read-write service object can be used as a first parameter of the constructor, and the socket transmitted into the read-write service object can be marked as m _ socket. The target IP address and the target port are imported into a connection function, such as an async _ connect function, in the created socket m _ socket by calling the connection function to connect to the target server. In this embodiment, the connection function of the socket is used to implement asynchronous connection to the target server, and a callback function of the onconnectidreult is also provided to determine whether the execution of the connection function is successful, and the first callback function is used to receive the connection result of the connection function. Optionally, when entering the first callback function, determining whether the target server is successfully connected by judging whether error parameter information in the first callback function is equal to 0. If the error parameter information is equal to 0, the connection target server is successful, and if the error parameter information is not equal to 0, the connection target server is failed, and the connection of the target server needs to be performed again.
Optionally, after the target server is successfully connected, a network read data request needs to be initiated to prepare for receiving the response data of the target server. That is, when a receiving function in the socket, such as the async _ read _ some function, is called, an asynchronous request for exclusive rights is posted to the read-write service object. And when the receiving function is called, a callback function of the OnRecvMessage is also required to be provided so as to receive the network data sent by the target server. In this embodiment, the receiving function async _ read _ some in the socket is used to implement asynchronous receiving and downloading of the network data sent by the target server.
Optionally, the preset request method is a GET method; correspondingly, generating a target request message according to the preset request method and the target website, and sending the target request message to a target server, wherein the method comprises the following steps:
constructing a GET head and a host head according to a target website; determining a target request message header according to the GET header and the host header; and sending the head of the target request message to the target server according to the sending function in the socket.
After the target server is successfully connected, the target request message can be sent to the target server. When the preset request mode is a GET method, the header data of the HTTP request message of the text type is usually sent to the target server. In the embodiment, the head of the request message needs to use the row break of \ r \ n ', and the tail of the text data has a row break of \ r \ n' without any data. When constructing the GET header, the GET string must be started, followed by the host name in the target web address and the version number of the HTTP protocol. When constructing the Host (Host) header, the Host character string is started, followed by the Host address in the target web address. Illustratively, if the target website address is HTTP:// www.douyu.com/pcclient/version.ini, the constructed GET header is GET pcclient/version.ini HTTP/1.1\ r \ n, and the constructed Host header is Host: www.douyu.com \ r \ n. And adding the constructed host head immediately after the constructed GET head so as to determine the text character string of the target request message head. The text string of the target request message header is sent to the target server by calling a send function in the socket, such as the async _ write _ some function. The sending function async _ write _ some in the socket in this embodiment is used to implement asynchronous sending of the request data.
Optionally, after S120, the method further includes:
and calling a receiving function in the socket, and receiving a target response message sent by the target server by using the second callback function.
After the target request message is sent to the target server, if the target server responds successfully, the target server sends a target response message corresponding to the target request message to the file downloading device. In this embodiment, the receiving function async _ read _ some in the socket is called, and when the target server responds successfully, the target server enters the second callback function OnRecvMessage to receive the target response message sent by the target server.
S130, determining a target response code according to the received target response message, wherein the target response message is sent by the target server according to the target request message.
The target response message in this embodiment refers to an HTTP response message generated and sent by the target server according to the target request message. The target response code may be used to describe a request result returned when the request is sent to the target server, and it may be determined whether the target server successfully processes the request or has an error according to the target response code. When receiving the target response message, analyzing the target response message, and determining the target response code in the target request message. In the target response message, the HTTP version number is started, and the target response code is immediately followed by the HTTP version number. Illustratively, if the target response message is "HTTP/1.1200", the target response code is determined to be 200, and if the target response message is "HTTP/1.1302", the target response code is determined to be 302. When the target response code is 200, it indicates that the target server has successfully processed the request. If the target response code is 302, it indicates that the target website of the file to be downloaded has a redirection error, i.e. the target website has been transferred.
S140, if the target response code is the transfer response code, determining a transfer website according to the target response message, updating the target request message according to the transfer website, and sending the updated target request message to the target server.
The transfer response code refers to a corresponding response code when the website is transferred, and the transfer response code in this embodiment may be 302. When the target response code is the transfer response code, it indicates that a redirection error occurs, that is, the file to be downloaded cannot be successfully downloaded according to the target website, and at this time, the transfer website needs to be determined according to the target response message. Optionally, the Location field in the header of the target response packet is analyzed, and the redirected transfer website is obtained. Illustratively, the target address of the file version.ini to be downloaded is http:// www.douyu.com/pcclient/version.ini, which means that the file version.ini to be downloaded is stored in the pcclient directory of the www.douyu.com host, if the file version.ini to be downloaded is moved to the pcclient2 directory for some reason, the Location field in the header of the target response message acquired at this time is "Location: http:// www.douyu.com/pcclient 2/version.ini", and the transfer address can be determined to be http:// www.douyu.com/pcclient2/version.ini according to the Location field, so that the file version.ini to be downloaded can be re-downloaded according to the transfer address. In this embodiment, the step of updating the target transfer website with the target request message refers to updating the target website to the transfer website, and re-entering step S120, generating an updated target request message according to the preset request method and the updated target website, and re-sending the updated target request message to the target server to receive an updated target response message sent by the target server according to the updated target request message.
And S150, downloading the file to be downloaded according to the received updated target response message.
The target response code in the updated target response message obtained according to the transfer website is the successful response code 200, that is, the file resource of the file to be downloaded is successfully obtained. In this embodiment, it may also be determined whether the target response code in the updated target response message is a successful response code, and if so, the file to be downloaded is downloaded according to the updated target response message, so as to ensure the accuracy of downloading the file.
Optionally, S150 includes:
creating a target file with the same name as a file to be downloaded in the transfer website at a preset position of the disk; determining target size information of the file to be downloaded according to length field information in the head of the updated target response message; calling a receiving function of the socket and a poll method in the read-write service object, and transmitting target size information into the receiving function to download data information of a file to be downloaded; and writing the downloaded data information into the target file.
The preset position of the disk refers to a download position of a file to be downloaded, and the preset position can be a storage position in the disk selected by a user in advance according to actual requirements. And analyzing the updated target website to obtain the file name of the file to be downloaded, such as version. An object file with the same name as the file name, such as a version. Because the target response code in the updated target response message is a successful response code, the header of the obtained updated target response message must have Length field information, such as a Content-Length field, and the target size information of the file to be downloaded is determined according to the Content-Length field. Illustratively, if the obtained Content-Length field is "Content-Length: 1000", it indicates that the target size of the file to be downloaded is 1000 bytes. The target size information in this embodiment may be determined before the target file is created, or may be determined after the target file is created, and the order of the determining step of the target size information and the creating step of the target file is not specifically limited in this embodiment.
In this embodiment, a receiving function of the socket and a poll method in the read-write service object need to be simultaneously called, so that the second callback function OnRecvMessage receives file data sent by the target server, and if only the receiving function of the socket is called and the poll method in the read-write service object is not called, the second callback function OnRecvMessage cannot receive the file data. By calling a receiving function async _ read _ some of the socket and a poll method in the read-write service object and transmitting the target size information into the receiving function async _ read _ some, the data information of the file to be downloaded can be received by using a second callback function OnRecvMessage, and when the downloaded byte quantity is equal to the target size information, the downloading of the file to be downloaded is finished. After the data information of the file to be downloaded is downloaded on the target server, the data information of the file to be downloaded is written into the created target file by calling the fwrite function, so that the file to be downloaded is stored. In the embodiment, when the HTTP file is downloaded, if a redirection error occurs, the redirected transfer website can be automatically analyzed, and the redirected file is automatically downloaded again according to the transfer website, so that the problem that the redirected file cannot be automatically downloaded in the prior art is solved, the downloading efficiency is greatly accelerated, and the user experience is improved.
It should be noted that in this embodiment, the connection function async _ connect, the receiving function async _ read _ some, and the sending function async _ write _ some that call a socket are all asynchronous, so that a poll method of a read-write service object needs to be called to process all asynchronous events of the socket.
Optionally, if the target response code is a successful response code, the file to be downloaded is directly downloaded according to the target response message.
The successful response code in this embodiment may be 200. If the target response code in the target response message is a successful response code, it indicates that no redirection error occurs in the file to be downloaded, and at this time, the file to be downloaded can be directly downloaded according to the target response message. The process of directly downloading the file according to the target response message is similar to the process of downloading the file according to the updated target response message, and specifically comprises the following steps: creating a target file with the same name as a file to be downloaded in a target website at a preset position of a magnetic disk; determining target size information of a file to be downloaded according to length field information in a header of a target response message; calling a receiving function of the socket and a poll method in the read-write service object, and transmitting target size information into the receiving function to download data information of a file to be downloaded; and writing the downloaded data information into the target file. According to the embodiment, the file can be automatically downloaded according to different target response codes by judging whether the target response codes are transfer response codes or successful response codes, so that the running stability and the applicability of the downloading system are improved.
According to the technical scheme of the embodiment, a target request message is generated according to a preset request method and a target website of a file to be downloaded, the target request message is sent to a target server, and a target response code is determined according to a received target response message; if the target response code is the transfer response code, determining a transfer website according to the target response message, updating the target request message according to the transfer website, and resending the updated target request message to the target server to receive the updated target response message, so that the file to be downloaded is downloaded according to the updated target response message, and when the target website of the file to be downloaded is redirected, the file to be downloaded can be automatically downloaded according to the redirected transfer website, thereby solving the problem that the redirected file cannot be automatically downloaded in the prior art, improving the downloading efficiency and improving the user experience.
Example two
Fig. 2 is a schematic structural diagram of a file downloading device according to a second embodiment of the present invention, where the present embodiment is applicable to a case where a file in a server is downloaded in a client, and the device includes: a target website acquisition module 210, a target request message generation module 220, a target response code determination module 230, a target request message update module 240, and a first file download module 250.
The target website acquiring module 210 is configured to acquire a target website corresponding to a file to be downloaded; a target request message generating module 220, configured to generate a target request message according to a preset request method and a target website, and send the target request message to a target server; a target response code determining module 230, configured to determine a target response code according to the received target response message, where the target response message is sent by the target server according to the target request message; a target request message updating module 240, configured to determine a transfer website according to the target response message if the target response code is a transfer response code, update the target request message according to the transfer website, and send the updated target request message to the target server; and a first file downloading module 250, configured to download the file to be downloaded according to the received updated target response packet.
Optionally, the target request packet generating module 220 includes:
the target IP address determining unit is used for determining a target IP address and a target port according to a target domain name address in a target website;
a target server connection unit for connecting a target server using a socket and a read-write service object based on a target IP address and a target port;
and the target server connecting unit is used for generating a target request message according to the preset request method and the target website and sending the target request message to the target server when the target server is successfully connected.
Optionally, the target server connection unit is specifically configured to:
establishing an asynchronous read-write service object; creating an asynchronous socket and transmitting a read-write service object into a construction function of the socket; calling a connection function of the socket, and transmitting a target IP address and a target port into the connection function; and determining whether the target server is successfully connected according to the parameter information in the first callback function, wherein the first callback function is used for receiving the connection result of the connection function.
Optionally, the preset request method is a GET method; correspondingly, the target request message generating unit is specifically configured to:
constructing a GET head and a host head according to a target website; determining a target request message header according to the GET header and the host header; and sending the head of the target request message to the target server according to the sending function in the socket.
Optionally, the apparatus further comprises:
and the target response message receiving module is used for calling a receiving function in the socket after the target request message is sent to the target server, and receiving the target response message sent by the target server by using the second callback function.
Optionally, the first file downloading module 250 is specifically configured to:
creating a target file with the same name as a file to be downloaded in the transfer website at a preset position of the disk;
determining target size information of the file to be downloaded according to length field information in the head of the updated target response message;
calling a receiving function of the socket and a poll method in the read-write service object, and transmitting target size information into the receiving function to download data information of a file to be downloaded;
and writing the downloaded data information into the target file.
Optionally, the apparatus further comprises:
and the second file downloading module is used for directly downloading the file to be downloaded according to the target response message if the target response code is the successful response code.
The file downloading device can execute the file downloading method provided by any embodiment of the invention, and has the corresponding functional modules and beneficial effects of executing the file downloading method.
EXAMPLE III
Fig. 3 is a schematic structural diagram of a terminal according to a third embodiment of the present invention. Referring to fig. 3, the terminal includes:
one or more processors 310;
a memory 320 for storing one or more programs;
when executed by the one or more processors 310, cause the one or more processors 310 to implement the file download method as set forth in any of the above embodiments.
In FIG. 3, a processor 310 is illustrated as an example; the processor 310 and the memory 320 in the terminal may be connected by a bus or other means, for example, in fig. 3.
The memory 320 is a computer-readable storage medium, and can be used for storing software programs, computer-executable programs, and modules, such as program instructions/modules corresponding to the file downloading method in the embodiment of the present invention (for example, the target website acquiring module 210, the target request message generating module 220, the target response code determining module 230, the target request message updating module 240, and the first file downloading module 250 in the file downloading device). The processor 310 executes various functional applications of the terminal and data processing, i.e., implements the above-described file download method, by executing software programs, instructions, and modules stored in the memory 320.
The memory 320 mainly includes a program storage area and a data storage area, wherein the program storage area can store an operating system and an application program required by at least one function; the storage data area may store data created according to the use of the terminal, and the like. Further, the memory 320 may include high speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other non-volatile solid state storage device. In some examples, the memory 320 may further include memory located remotely from the processor 310, which may be connected to the terminal over a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The terminal proposed by the embodiment and the file downloading method proposed by the embodiment belong to the same inventive concept, and technical details that are not described in detail in the embodiment can be referred to the embodiment, and the embodiment has the same beneficial effects as the file downloading method.
Example four
The present embodiment provides a computer-readable storage medium on which a computer program is stored, which when executed by a processor implements a file download method according to any of the embodiments of the present invention.
Computer storage media for embodiments of the invention may employ any combination of one or more computer-readable media. The computer readable medium may be a computer readable signal medium or a computer readable storage medium. The computer-readable storage medium may be, for example but not limited to: an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples (a non-exhaustive list) of the computer readable storage medium would include the following: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
A computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
Computer program code for carrying out operations for aspects of the present invention may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
The above example numbers are for description only and do not represent the merits of the examples.
It will be understood by those skilled in the art that the modules or steps of the invention described above may be implemented by a general purpose computing device, they may be centralized on a single computing device or distributed across a network of computing devices, and optionally they may be implemented by program code executable by a computing device, such that it may be stored in a memory device and executed by a computing device, or it may be separately fabricated into various integrated circuit modules, or it may be fabricated by fabricating a plurality of modules or steps thereof into a single integrated circuit module. Thus, the present invention is not limited to any specific combination of hardware and software.
The embodiments in the present specification are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same or similar parts in the embodiments are referred to each other.
It is to be noted that the foregoing is only illustrative of the preferred embodiments of the present invention and the technical principles employed. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, although the present invention has been described in greater detail by the above embodiments, the present invention is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the present invention, and the scope of the present invention is determined by the scope of the appended claims.

Claims (9)

1. A method for downloading a file, comprising:
acquiring a target website corresponding to a file to be downloaded;
generating a target request message according to a preset request method and the target website, and sending the target request message to a target server;
generating a target request message according to a preset request method and the target website, and sending the target request message to a target server, wherein the method comprises the following steps:
determining a target IP address and a target port according to a target domain name address in the target website;
determining a target IP address and a target port according to a target domain name address in the target website, comprising:
transmitting the target domain name address serving as a parameter to a gethostbyname function through a gethostbyname network application programming interface so as to obtain a host structure data, calling inet _ ntoa to obtain h _ addr _ list [0] according to an h _ addr _ list field in the host structure, and determining the IP address corresponding to the h _ addr _ list [0] as the target IP address corresponding to the target domain name address;
based on the target IP address and the target port, connecting a target server by utilizing a socket and a read-write service object;
when the target server is successfully connected, generating a target request message according to a preset request method and the target website, and sending the target request message to the target server;
determining a target response code according to the received target response message, wherein the target response message is sent by the target server according to the target request message;
if the target response code is a transfer response code, determining a transfer website according to the target response message, updating the target request message according to the transfer website, and sending the updated target request message to the target server;
and downloading the file to be downloaded according to the received updated target response message.
2. The method of claim 1, wherein connecting a target server using a socket and a read-write service object based on the target IP address and the target port comprises:
establishing an asynchronous read-write service object;
creating an asynchronous socket and transmitting the read-write service object into a constructor of the socket;
calling a connection function of the socket, and transmitting the target IP address and the target port into the connection function;
and determining whether the target server is successfully connected according to parameter information in a first callback function, wherein the first callback function is used for receiving a connection result of the connection function.
3. The method of claim 1, wherein the predetermined request method is a GET method;
correspondingly, generating a target request message according to a preset request method and the target website, and sending the target request message to the target server, including:
constructing a GET head and a host head according to the target website;
determining a target request message header according to the GET header and the host header;
and sending the target request message header to the target server according to the sending function in the socket.
4. The method of claim 1, further comprising, after sending the target request message to the target server:
and calling a receiving function in the socket, and receiving a target response message sent by the target server by using a second callback function.
5. The method according to claim 1, wherein downloading the file to be downloaded according to the received updated target response message comprises:
creating a target file with the same name as the file to be downloaded in the transfer website at a preset position of the disk;
determining the target size information of the file to be downloaded according to the length field information in the head of the updated target response message;
calling a receiving function of the socket and a poll method in the read-write service object, and transferring the target size information into the receiving function to download the data information of the file to be downloaded;
and writing the downloaded data information into the target file.
6. The method according to any one of claims 1-5, further comprising:
and if the target response code is a successful response code, directly downloading the file to be downloaded according to the target response message.
7. A file downloading apparatus, comprising:
the target website acquisition module is used for acquiring a target website corresponding to the file to be downloaded;
the target request message generation module is used for generating a target request message according to a preset request method and the target website and sending the target request message to a target server;
the target request message generation module comprises:
the target IP address determining unit is used for determining a target IP address and a target port according to a target domain name address in a target website;
determining a target IP address and a target port according to a target domain name address in the target website, comprising:
transmitting the target domain name address serving as a parameter to a gethostbyname function through a gethostbyname network application programming interface so as to obtain a host structure data, calling inet _ ntoa to obtain h _ addr _ list [0] according to an h _ addr _ list field in the host structure, and determining the IP address corresponding to the h _ addr _ list [0] as the target IP address corresponding to the target domain name address;
the target server connection unit is used for connecting a target server by utilizing a socket and a read-write service object based on a target IP address and a target port, and is also used for generating a target request message according to a preset request method and a target website and sending the target request message to the target server when the target server is successfully connected;
a target response code determining module, configured to determine a target response code according to a received target response message, where the target response message is sent by the target server according to the target request message;
a target request message updating module, configured to determine a transfer website according to the target response message if the target response code is a transfer response code, update the target request message according to the transfer website, and send the updated target request message to the target server;
and the first file downloading module is used for downloading the file to be downloaded according to the received updated target response message.
8. A terminal, characterized in that the terminal comprises:
one or more processors;
a memory for storing one or more programs;
when executed by the one or more processors, cause the one or more processors to implement the file download method as claimed in any one of claims 1-6.
9. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out a file download method according to any one of claims 1 to 6.
CN201810396790.8A 2018-04-28 2018-04-28 File downloading method, device, terminal and storage medium Active CN108600378B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810396790.8A CN108600378B (en) 2018-04-28 2018-04-28 File downloading method, device, terminal and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810396790.8A CN108600378B (en) 2018-04-28 2018-04-28 File downloading method, device, terminal and storage medium

Publications (2)

Publication Number Publication Date
CN108600378A CN108600378A (en) 2018-09-28
CN108600378B true CN108600378B (en) 2021-05-28

Family

ID=63611000

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810396790.8A Active CN108600378B (en) 2018-04-28 2018-04-28 File downloading method, device, terminal and storage medium

Country Status (1)

Country Link
CN (1) CN108600378B (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112968919B (en) * 2019-12-12 2023-05-30 上海欣诺通信技术股份有限公司 Data processing method, device, equipment and storage medium
CN111813851B (en) * 2020-05-25 2023-10-20 车智互联(北京)科技有限公司 Method, system and mobile terminal for synchronizing data from mobile application to webpage
CN112788141B (en) * 2021-01-18 2022-07-05 苏州浪潮智能科技有限公司 File downloading method, device, equipment and computer readable storage medium

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104219311A (en) * 2014-09-05 2014-12-17 四川长虹电器股份有限公司 Method and system for downloading television application
CN104270440A (en) * 2014-09-26 2015-01-07 郭丹 Portal processing method of portable broadband wireless access equipment
CN104426718A (en) * 2013-09-10 2015-03-18 方正宽带网络服务股份有限公司 Data monitoring server, cache server and redirection downloading method
CN104468363A (en) * 2013-09-18 2015-03-25 华为终端有限公司 Page redirection method, page redirection system, router equipment and terminal equipment
CN106557584A (en) * 2016-11-29 2017-04-05 青岛海信移动通信技术股份有限公司 A kind of web site collection method and device
CN106874471A (en) * 2017-02-16 2017-06-20 北京百度网讯科技有限公司 Information-pushing method and device
CN107196986A (en) * 2016-03-15 2017-09-22 中国移动通信集团江苏有限公司 A kind of reorientation method and device

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8484373B2 (en) * 2010-10-25 2013-07-09 Google Inc. System and method for redirecting a request for a non-canonical web page

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104426718A (en) * 2013-09-10 2015-03-18 方正宽带网络服务股份有限公司 Data monitoring server, cache server and redirection downloading method
CN104468363A (en) * 2013-09-18 2015-03-25 华为终端有限公司 Page redirection method, page redirection system, router equipment and terminal equipment
CN104219311A (en) * 2014-09-05 2014-12-17 四川长虹电器股份有限公司 Method and system for downloading television application
CN104270440A (en) * 2014-09-26 2015-01-07 郭丹 Portal processing method of portable broadband wireless access equipment
CN107196986A (en) * 2016-03-15 2017-09-22 中国移动通信集团江苏有限公司 A kind of reorientation method and device
CN106557584A (en) * 2016-11-29 2017-04-05 青岛海信移动通信技术股份有限公司 A kind of web site collection method and device
CN106874471A (en) * 2017-02-16 2017-06-20 北京百度网讯科技有限公司 Information-pushing method and device

Also Published As

Publication number Publication date
CN108600378A (en) 2018-09-28

Similar Documents

Publication Publication Date Title
CN104063239B (en) Application program update method and server, the client of mobile terminal
CN108600377B (en) Method, device, terminal and storage medium for suspending file downloading
CN110442524B (en) Method and device for testing web service interface with authentication authorization
US11232405B2 (en) Computer readable storage media for dynamic service deployment and methods and systems for utilizing same
CN109496418B (en) File downloading method and device, and equipment/terminal/server
CN108600378B (en) File downloading method, device, terminal and storage medium
CN104219316A (en) Method and device for processing call request in distributed system
WO2011076146A1 (en) Method for downloading application data, digital television reception terminal and system
CN112565439B (en) Internet of things communication method and system
CN108920157B (en) Nginx software installation method and device, computer equipment and storage medium
CN112954717A (en) Household appliance network distribution method and device based on H5 page
CN108595574B (en) Database cluster connection method, device, equipment and storage medium
CN112748962B (en) Application loading method, device, electronic equipment and computer readable medium
CN105677688B (en) Page data loading method and system
US9754327B2 (en) Method and apparatus for configuring social networking site sharing functions
CN108370500B (en) Optimized settings for wireless devices
CN112187869A (en) Remote debugging system and method of IOT device, electronic device and storage medium
Sarker et al. Learning Python Network Programming
US20170168923A1 (en) System and method for creating a test application
CN108509243A (en) The method, apparatus and electronic equipment of a kind of page load in application
CN114338461A (en) Network connection monitoring method and related equipment
CN113746851A (en) Agent system and method for supporting real-time analysis of GRPC request
CN110597540A (en) Version updating method and device of financial terminal, server and storage medium
CN111953793B (en) Application distribution method, device, terminal and storage medium
CN110224973B (en) Multi-server parallel implementation method based on programming game, electronic equipment and medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant