A network request processing method, device, and storage medium
By generating a circular link after the network request fails and using the network layer protocol to detect the connectivity status, the problem of frequent retry after the network request fails is solved, which improves the request success rate and reduces traffic consumption and system pressure.
Patent Information
- Application Number
- CN202110954419.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-19
- Publication Date
- 2025-07-18
- Estimated Expiration
- 2041-08-19
AI Technical Summary
In the case of abnormal network status, frequent retry after network request failure results in lost data requests, low success rate of secondary requests, consume network traffic and affect the operation of the application.
By generating the target recurrent linked list to store the data of network request failures, the network connection status is detected using the preset network layer protocol, and the network request is resent after the connection is detected, avoiding frequent sending.
It improves the success rate of network retry, reduces traffic consumption and server system pressure, and improves data processing efficiency.
Smart Images

Figure CN115714633B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of Internet technologies, and in particular, to a network request processing method, apparatus, and storage medium. Background Art
[0002] In the case of abnormal network status, network requests often fail to respond, and no effective network data can be obtained, which may further cause program crashes, lags, abnormal page displays, etc. In the current solutions, after a network request fails, the request will be continuously resent until the request is successful or a certain number of request attempts are reached for immediate network retry. In this solution, data requests are likely to be lost, the probability of successful retry of the secondary request is low, and network traffic is consumed during the continuous retry process, which also affects the normal operation and use of the application program.
[0003] Therefore, an improved network request processing solution is needed to solve the above technical problems. Summary of the Invention
[0004] This application provides a network request processing method, apparatus, and storage medium, which can avoid frequent sending of the same network request during the retry process and improve the success rate of secondary requests.
[0005] On the one hand, this application provides a network request processing method, which is applied to a terminal. The method includes:
[0006] Obtain the first response status of a network request initiated by an application program;
[0007] If the first response status is a response failure, generate corresponding target request data in a target circular linked list based on the request parameter information of the network request;
[0008] Detect the network connectivity status according to a preset network layer protocol and the target request data stored in the target circular linked list;
[0009] When network connectivity is detected, resend the target network request corresponding to the target request data.
[0010] On the other hand, a network request processing apparatus is provided. The apparatus includes:
[0011] A response status determination module: used to obtain the first response status of a network request initiated by an application program;
[0012] A request data generation module: used to generate corresponding target request data in a target circular linked list based on the request parameter information of the network request if the first response status is a response failure;
[0013] Network connectivity detection module: used to detect the network connectivity status according to the preset network layer protocol and the target request data stored in the target circular linked list;
[0014] Network request retry module: used to resend the target network request corresponding to the target request data when network connectivity is detected.
[0015] On the other hand, a network request processing device is provided. The device includes a processor and a memory. At least one instruction or at least one program segment is stored in the memory. The at least one instruction or the at least one program segment is loaded and executed by the processor to implement the network request processing method as described above.
[0016] On the other hand, a computer-readable storage medium is provided. At least one instruction or at least one program segment is stored in the storage medium. The at least one instruction or the at least one program segment is loaded and executed by a processor to implement the network request processing method as described above.
[0017] On the other hand, a terminal is provided. The terminal includes a processor and a memory. At least one instruction or at least one program segment is stored in the memory. The at least one instruction or the at least one program segment is loaded and executed by the processor to implement the network request processing method as described above.
[0018] The network request processing method, device, equipment, storage medium and terminal provided by this application have the following technical effects:
[0019] This application obtains the first response status of the network request initiated by the application program; if the first response status is a response failure, corresponding target request data is generated in the target circular linked list based on the request parameter information of the network request; the network connectivity status is detected according to the preset network layer protocol and the target request data stored in the target circular linked list; when network connectivity is detected, the target network request corresponding to the target request data is resent. Before network retry, the terminal first judges whether the network is connected based on the network layer protocol, and then executes network request retry after detecting connectivity, which can avoid the frequent sending of the same network request during the retry process, improve the success rate of the second request, reduce traffic consumption and the pressure on the server system, and store the target request data based on the circular linked list, so that the corresponding network detection and network retry can be automatically executed in a loop without additional monitoring and loop trigger operations, effectively improving data processing efficiency. Description of the Drawings
[0020] To more clearly illustrate the technical solutions and advantages in the embodiments of the present application or the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, the drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained based on these drawings.
[0021] Figure 1 It is a schematic diagram of an application environment provided by an embodiment of the present application;
[0022] Figure 2 It is a schematic flowchart of a network request processing method provided by an embodiment of the present application;
[0023] Figure 3 It is a schematic diagram of a page when a network request of an application program fails provided by an embodiment of the present application;
[0024] Figure 4 is Figure 3 a schematic diagram of a page when another network request of the corresponding application program fails in
[0025] Figure 5 It is a schematic flowchart of a target request data generation method provided by an embodiment of the present application;
[0026] Figure 6 It is a schematic flowchart of a network connectivity status detection method provided by an embodiment of the present application;
[0027] Figure 7 It is a schematic flowchart of a target network request generation method provided by an embodiment of the present application;
[0028] Figure 8 It is a schematic flowchart of another network request processing method provided by an embodiment of the present application;
[0029] Figure 9 It is a schematic flowchart of a network request processing method provided by an embodiment of the present application;
[0030] Figure 10 It is a schematic structural diagram of a network request processing device provided by an embodiment of the present application;
[0031] Figure 11 It is a hardware structure block diagram of an electronic device for a network request processing method provided by an embodiment of the present application. Detailed implementation manners
[0032] The following will clearly and completely describe the technical solutions in the embodiments of the present application with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments in the present application without creative efforts belong to the scope of protection of the present application.
[0033] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned accompanying drawings are used to distinguish similar objects, and do not necessarily need to be used to describe a specific order or sequence. It should be understood that such used data can be interchanged under appropriate circumstances so that the embodiments of the present application described here can be implemented in an order other than those illustrated or described here. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or server including a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products, or devices.
[0034] Before further elaborating on the embodiments of the present application, the nouns and terms involved in the embodiments of the present application are described. The nouns and terms involved in the embodiments of the present application are applicable to the following explanations.
[0035] DNS: (Domain Name System, domain name resolution service), a functional service that resolves domain names into IP addresses.
[0036] Circular linked list: A circular linked list is a chained storage structure. Its characteristic is that the pointer field of the last node (Node) in the list points to the head node, and the entire linked list forms a ring.
[0037] ICMP: ICMP (Internet Control Message Protocol). It is a sub-protocol of the TCP / IP protocol suite and is used to transfer control messages between IP hosts and routers. Control messages refer to messages about the network itself, such as whether the network is accessible, whether the host is reachable, and whether the route is available.
[0038] Please refer to Figure 1 , Figure 1 which is a schematic diagram of an application environment provided by the embodiments of the present application, as Figure 1As shown, the application environment may at least include a terminal 01 and a server 02. In practical applications, the terminal 01 and the server 02 may be directly or indirectly connected through wired or wireless communication means to achieve the interaction between the terminal 01 and the server 02, and this application does not limit this here.
[0039] In the embodiments of this application, the terminal 01 may include physical devices such as smartphones, desktop computers, tablet computers, laptop computers, digital assistants, augmented reality (AR) / virtual reality (VR) devices, smart TVs, smart speakers, smart wearable devices, in-vehicle terminal devices, etc., or may also include software running on the physical devices, such as application programs, etc. Specifically, the terminal 01 may be used to send a network request to the server 02, and when it is determined that the network request fails, generate corresponding target request data in the target circular linked list based on the corresponding request parameter information, and perform corresponding network status connectivity detection and network request retry processing.
[0040] In the embodiments of this application, the server 02 may be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or may also be a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. Specifically, the server may include a physical device, which may specifically include a network communication unit, a processor, a memory, etc., or may also include software running on the physical device, which may specifically include application programs, etc. Specifically, the server 02 may be used to receive the network request sent by the terminal 01, and send response information and network data to the terminal 01 in response to the network request. Specifically, the server 02 may also be used to provide domain name resolution services, etc.
[0041] In addition, it should be noted that Figure 1 What is shown is only the application environment of a network request processing method, and this application environment may include more or fewer nodes, and this application does not limit this here.
[0042] The following introduces a network request processing method of this application based on the above application environment, which is applied to the terminal. Figure 2It is a schematic flowchart of a network request processing method provided by an embodiment of the present application. This specification provides method operation steps such as in the embodiment or flowchart, but based on routine or non-creative labor, there may be more or fewer operation steps. The step sequence listed in the embodiment is only one of the execution sequences of numerous steps and does not represent the only execution sequence. When the actual system or server product executes, it can be executed in the method sequence shown in the embodiment or the accompanying drawings or executed in parallel (such as in an environment with parallel processors or multi-threaded processing). Specifically, as Figure 2 shown, the method may include the following steps.
[0043] S201: Obtain the first response status of the network request initiated by the application program.
[0044] In the embodiment of the present application, when the application program of the terminal requests network data from the server, it needs to send a network request. Obtaining the first response status of each network request initiated by the application program, that is, monitoring whether the first response status of each network request is a callback success or a response failure. If the callback is successful, it indicates that the network data corresponding to the network request is obtained. If the response fails, it indicates that the network request fails.
[0045] S203: If the first response status is a response failure, generate corresponding target request data in the target circular linked list based on the request parameter information of the network request.
[0046] In the embodiment of the present application, in response to the response failure of the network request, a node is created in the target circular linked list, and after adding the request parameter information to the node, the corresponding target request data is generated. Specifically, the target request data includes the data required to regenerate and send the corresponding target network request. In the case of multiple network requests with response failures, corresponding multiple nodes are created in the target circular linked list, each node corresponding to a network request, and the target request data corresponding to each network request is generated. Specifically, the order of the target request data of multiple network requests in the target circular linked list, that is, the position of the newly created node, can be determined based on a preset order, such as based on time sequence, etc. Specifically, the order of the target request data of multiple network requests in the target circular linked list can also be determined according to the priority of the network request. This priority can be a priority customized by the business module of the application program; correspondingly, when obtaining the request parameter information, it is also necessary to obtain the target priority of the current network request, and based on this target priority and the priority of the network request corresponding to the target request data already existing in the target circular linked list, determine the target position of the current network request in the target circular linked list, and generate the target request data corresponding to the current network request at this target position. It can be understood that the target request data corresponding to the network request with the highest priority is located at the head of the data reading order in the target circular linked list.
[0047] In the embodiments of the present application, network request failures may include, but are not limited to, the following reasons: no network environment, directly failing after the network request is sent, and unable to receive the response information from the server; request timeout: errors occur during data transmission due to network environment reasons (such as a weak network environment); failure of the program business module: for example, if business module A requires data M but receives a subset of data M, it is determined as a network request failure. It should be noted that the reasons for network request failures are not limited to the above descriptions and may also include other factors that can cause network request failures, which are not restricted here.
[0048] In the embodiments of the present application, the request parameter information may at least include the destination domain name or the request host address (such as the URL address). Specifically, the request parameter information may also include one or more of the request status parameter, response identifier, protocol, request time parameter, response time parameter, page identifier, statistical data, and program custom data. In different network states, such as no network, weak network, timeout, or business module failure, the number of request parameters included in the request parameter information may be different. For example, more parameters are included in the timeout state, fewer parameters are included in the no-network state, and most of the request parameters are empty.
[0049] In some cases, in the application program that needs to generate network requests, for the same application program, all network requests have unified entry and exit processing. Exemplarily, business module A and business module B of the application program send network request A and network request B. Although the network data they request from the server is different, the network requests include common parameters such as device type, system version, and request time. These common parameters are encapsulated into a unified method for calling; when both network request A and network request B fail to respond, that is, page A and page B have network failures, both pages will display a failed loading diagram (please refer to Figure 3 and Figure 4 ), indicating that business module A and business module B also have a unified processing entry for network request callbacks. Correspondingly, when a network request failure occurs, the request parameter information of this request can be obtained at the entry where the network request is sent.
[0050] In the embodiments of the present application, the target circular linked list is a linked list used to store the request data of the application program in a certain order and supports operations such as inserting, deleting, reading, and modifying data. Specifically, the target circular linked list stores the request data corresponding to different network requests in units of nodes. Before step S203, the method further includes: creating the target circular linked list. In the initial state, the data in the target circular linked list is empty. In some cases, in response to the startup of the application program, the creation step of the target circular linked list is triggered.
[0051] In some embodiments, each node in the target circular linked list is configured with a separate memory space. Correspondingly, creating the target circular linked list may include: creating the target circular linked list based on a preset linked list construction method, and allocating memory for the nodes so that each node in the linked list corresponds to a separate memory space. In this way, operations such as searching, reading, modifying, and deleting requested data can be directly performed at the corresponding memory location, without first traversing the entire linked list data to determine the memory location of the requested data and then performing the corresponding operations, which can effectively improve the processing efficiency of the requested data.
[0052] In some embodiments, a predefined control tool class can be used to create the target circular linked list. Correspondingly, before creating the target circular linked list, a control tool class is created, which defines linked list attributes, linked list creation methods, linked list maintenance methods, request parameter parsing methods, network connectivity status detection methods, etc. In some cases, in response to the startup of the application, the control tool class is created and used to create the target circular linked list. Exemplarily, the control tool class can be specifically the NetControlCenter class (Network Control Center class).
[0053] In some embodiments, the target circular linked list can be a singly circular linked list or a doubly circular linked list. Correspondingly, the creation process of the target circular linked list can be: calling a preset linked list creation method to allocate memory for the linked list to create an empty linked list L, where the memory allocation method is to allocate independent memory space for each node, and creating an empty node as the head node, pointing to L. When a network request with a failed response is detected, a linked list node is created. In the case of multiple network requests with failed responses, the corresponding number of linked list nodes is created to generate the target request data. The order of node creation and the node positions can be determined based on the aforementioned preset order or priority method, which will not be elaborated here. Specifically, the target circular linked list can be maintained based on the aforementioned control tool class.
[0054] In practical applications, the node data in the target circular linked list can include data model objects. Correspondingly, please refer to Figure 5 , S203 may include the following steps.
[0055] S2031: Generate a request data model object in the target circular linked list based on a predefined model class.
[0056] In a specific embodiment, the model class defines the request parameters to be written, parameter conversion methods, data encapsulation methods for network requests, etc. Specifically, the request data of the network request is processed into a model object based on the predefined model class to obtain a request data model object, that is, a new node is created in the target circular linked list.
[0057] S2032: Add the request parameter information to the request data model object to obtain the target request data.
[0058] In a specific embodiment, the request parameter information may include at least one parameter. Each parameter in the request parameter information is respectively added to the corresponding parameter position in the request data model object to assign values to the parameters in the request data model object, so as to obtain the target request data and complete the creation and assignment of this node. Specifically, when the destination domain name is included in the request parameter information, the DNS method is used to resolve the destination domain name into the destination IP address and add it to the request data model object. If the domain name is not included or the resolution fails, the corresponding field in the request data model object is empty. Specifically, the destination IP address can be obtained by implementing the DNS function on the terminal, and DNS resolution processing can be performed based on the aforementioned control tool class, such as the NetControlCenter class.
[0059] In some embodiments, S2032 may specifically include the following steps.
[0060] S20321: Perform format conversion processing on the request parameter information to obtain the corresponding request parameter fields.
[0061] S20322: Add the request parameter fields to the target field position in the request data model object to obtain the target request data.
[0062] Specifically, perform format conversion processing on each parameter in the request parameter information based on the parameter conversion method defined by the model class to obtain the request parameter fields of each parameter. And write each request parameter field to the corresponding target field position in the request data model object to assign values to the parameters in the model object.
[0063] In some embodiments, the node data in the target circular linked list contains a NetModel object. If it is a doubly circular linked list, the node data also contains the necessary front and back pointers. The nodes in the circular linked list store the data packets of the target request data. Specifically, the parameter conversion method defined by the model class can be the initWithDict method, and the data model object can receive the externally passed request parameter information based on this method. Exemplarily, the data format of the request parameter information can be dictionary data.
[0064] In an example, the class definition of the model class of the NetModel object is shown in Table 1 below.
[0065] Table 1
[0066]
[0067] Among them, the URL is the requested host address, the DNSIP field is the destination IP address after DNS resolution, and autoData is the custom data of the service module. When the destination domain name and the custom data of the service module of the application are included in the request parameter information, the custom data is converted into a corresponding string based on the parameter conversion method and written into the autoData field, and the destination domain name is resolved into the destination IP through DNS and written into the DNSIP field. If the destination domain name is not included or the DNS resolution fails, the DNSIP field is empty.
[0068] It can be understood that when in a networkless state, most of the parameters in the request parameter information are empty. Correspondingly, in the target request data generated based on the class definitions in the above table, that is, most of the parameters in NetModel are also empty.
[0069] S205: Detect the network connectivity status according to the preset network layer protocol and the target request data stored in the target circular linked list.
[0070] In the embodiments of the present application, the target request data stored in the nodes of the target circular linked list can be traversed cyclically, and the network connectivity status of the corresponding network request can be detected for each target request data. It can be understood that the data request objects of different network requests may be different. Correspondingly, the destination domain name or the destination Host address is also different. Therefore, the network connectivity status can be detected separately for each network request. When there are multiple nodes in the target circular linked list, that is, when the target request data of multiple network requests is stored, the target parameters in each target request data can be obtained in sequence, and the network connectivity status is detected based on the target parameters.
[0071] The pointer field of the last node of the target circular linked list points to the head node, and the entire linked list forms a ring. When traversing to the last node and detecting the corresponding network connectivity status according to the target request data in the last node, it can automatically loop to the first node of the linked list and continue to detect the corresponding network connectivity status, without additionally monitoring the traversal of each target request data in the target circular linked list, nor triggering the traversal operation again when traversing to the last node, effectively improving the data processing efficiency.
[0072] In practical applications, when the target circular linked list is not empty, a thread for detecting the network connectivity status is started, and using this thread, network connectivity detection is performed based on the target parameters.
[0073] In some cases, a timer is also started while starting the thread. The timer is used to time the time interval for obtaining adjacent target request data, and based on this time interval, the target parameters of each target request data in the target circular linked list are obtained in sequence. Specifically, the execution of the thread can be controlled based on the aforementioned control utility class.
[0074] In some embodiments, a thread can be started through the initWithTarget method of NSThread to handle the detection of the corresponding network connectivity status and the retry of network requests in the target circular linked list.
[0075] In practical applications, the target request data includes the destination IP address, and the aforementioned target parameter is the destination IP address. Correspondingly, please refer to Figure 6 , S205 may include the following steps.
[0076] S2051: Obtain the destination IP addresses of the respective target request data stored in the target circular linked list.
[0077] S2052: According to the preset network layer protocol and the destination IP address, and based on the data storage order in the target circular linked list, circularly detect the network connectivity status corresponding to each target request data.
[0078] In a specific embodiment, the preset network layer protocol defines the detection method of the network connectivity status and can also define the corresponding communication rules. This protocol is used to detect whether the destination IP address can be directly accessed. The preset network layer protocol can be the ICMP protocol or the like.
[0079] It can be understood that the transmission of network requests uses the protocol of the transport layer and consumes traffic, while the protocol of the network layer does not consume traffic. Therefore, using the protocol of the network layer to detect the network connectivity status can reduce the traffic cost and data transmission cost. Although the traffic required to resend network requests is not large, for clients with a high number of users (such as in the hundreds of millions), the traffic of network requests resent by a large number of users due to network failures is still very considerable. By using the protocol of the network layer to detect the network connectivity status and then resending the network requests after successful detection, not only can the traffic consumption be reduced, but also the data processing volume and system pressure on the server side can be reduced.
[0080] In some embodiments, S2052 may specifically include the following steps.
[0081] S20521: Generate a packet echo request corresponding to each target request data according to the preset network layer protocol and the destination IP address.
[0082] S20522: Circularly send the packet echo requests corresponding to the respective target request data based on the data storage order in the target circular linked list;
[0083] S20523: Determine the network connectivity status corresponding to each target request data according to the response information of the packet echo request.
[0084] Specifically, based on the definition of the preset network layer protocol, a corresponding packet echo request is generated according to the destination IP address of each target request data in the target circular linked list, and the packet echo request is sent based on the data storage order. Furthermore, based on the response information of the packet echo request, the network connectivity status corresponding to each target request data, that is, the network connectivity status of the corresponding network request, is determined. Specifically, the packet echo request can be sent in the forward or reverse order of the data storage order.
[0085] In some embodiments, the preset network layer protocol is the ICMP protocol, which is a network layer protocol; correspondingly, a ping command is executed on the destination IP address based on the ICMP protocol to generate a packet echo request for network connectivity status detection. The ping command is a detection method in the ICMP protocol. Correspondingly, the response information is an echo reply. When the value of the type field returned in the echo reply is 0, it means the destination host is reachable, that is, the network connectivity status is connected, otherwise the network connectivity status is abnormal. Specifically, when the target circular linked list is not empty, a thread and a timer can be started to execute the ping command on the destination IP. Specifically, the various commands of ICMP can be executed based on the above control tool class.
[0086] S207: When network connectivity is detected, resend the target network request corresponding to the target request data.
[0087] In the embodiments of the present application, the network connectivity status of each target request data in the target circular linked list is detected. When the result of a network connectivity status detection is detected as connected, the target request data corresponding to this network connectivity status detection is read from the target circular linked list, and the target request data is converted into the format required for the network request to generate a target network request, and the target network request is sent for network request retry. If the network connectivity status corresponding to the target request data is detected as abnormal, the network connectivity status detection continues to be performed based on the way of circularly traversing the target circular linked list.
[0088] Based on the above technical solution, when the network request fails, the second network request is not immediately made. By establishing a target circular linked list and storing the data for network connectivity status detection (such as the destination IP address obtained through DNS resolution) and the data required for regenerating and sending the network request (that is, the data required for network request retry) in the target circular linked list, and then performing network connectivity detection first. Under the condition of detecting a network connectivity request, the network request is regenerated and sent again, which can perform network retry without consuming network traffic, and avoid the frequent sending of the same network request and the loss of request data during the retry process, improving the network retry processing efficiency and the success rate of the secondary request.
[0089] In practical applications, please refer to Figure 7 , S207 may include the following steps.
[0090] S2071: If it is detected that the network connection status corresponding to any target request data is connected, the corresponding target request data is retrieved from the target circular linked list.
[0091] S2072: Generate a corresponding target network request according to the target request data and send the target network request.
[0092] It should be noted that the above-mentioned destination IP address (destination parameter) may not exist in the target request data, such as the DNSIP field being empty. The relevant reasons can be: the network request does not include the destination domain name; DNS resolution fails; the network request includes the destination domain name, but it is unable to communicate with the DNS server for DNS resolution in the no-network state, etc. It can be understood that the terminal can also pre-store the mapping relationship between the destination domain name and the destination IP address. In the no-network state, DNS resolution can also be performed through this local mapping relationship. When the mapping relationship stores the destination domain name to be resolved, DNS resolution failure will also occur. In the case where the destination IP address does not exist, the network connection status detection is not performed.
[0093] Correspondingly, please refer to Figure 8 , before step S205, the method may further include the following steps.
[0094] S209: If any target request data in the target circular linked list does not include the destination IP address, the corresponding target request data is retrieved from the target circular linked list.
[0095] S211: Generate a corresponding target network request according to the target request data and send the target network request.
[0096] In the embodiment of the present application, in the case where the destination IP address does not exist, that is, when the IP address field is empty, the corresponding target request data is directly retrieved from the target circular linked list, a target network request is generated, and the request is sent based on the destination URL address therein to perform a network request retry.
[0097] Specifically, based on the definition of the foregoing Table 1 model class, if the DNSIP field is not empty, first perform a ping command operation on the destination IP address based on the ICMP protocol. When the value of the returned type field is 0, it means the host is reachable. Then, the corresponding target request data is retrieved from the target circular linked list, and a corresponding target network request is generated and sent according to the target request data to perform a network retry; if it is found that the DNSIP field is empty, the corresponding target request data is directly retrieved to generate a target network request, and the request is attempted to be sent based on the destination URL address corresponding to the URL field therein to perform a network retry.
[0098] In some or all of the above embodiments, in the embodiments of the present application, after generating a corresponding target network request according to the target request data and sending the target network request, the method may further include the following steps.
[0099] S213: Monitor the second response status of the target network request.
[0100] S215: When the second response status is a successful response, delete the corresponding target request data from the target circular linked list.
[0101] In the embodiments of the present application, during the process of traversing the target request data in the target circular linked list and detecting the network connectivity status and / or resending the network request for each target request data, it is necessary to monitor the second response status of each sent target network request. When the second response status is a failed response, the target request data in the target circular linked list is retained, and the corresponding operations are continued based on the foregoing technical solutions. When the second response status is a successful response, that is, when the target network request callback is successful, the corresponding target request data is deleted from the target circular linked list. When the data in the target circular linked list is empty, the network request retry corresponding to all target request data is completed. In the case of using threads and timers, in response to the linked list data being empty, the thread and timer are closed.
[0102] Specifically, the target request data is stored in a node in the form of a data packet. When the network request fails at the terminal, the destination IP address is resolved through DNS, and the destination IP address and the data packet containing other request parameters are put into the target circular linked list. A child thread is started to check the connection to the destination IP address through the ICMP protocol. When it is found that the destination can be accessed, the corresponding data packet is taken out to generate and send a network request. After the request is successful, the node in the target circular linked list is deleted. In one example, the network connectivity status is detected through the ping command. Based on the model class definition in Table 1 above, after the ping is successful, the data packet of the target request data in the node is taken out, and the data packet is parsed into the corresponding format of the HTTP message. It is necessary to deserialize the custom data in the autoData field into json data, and then put it into the native request service parameters to generate and send the target network request. After the callback is successful, the corresponding node in the target circular linked list is deleted. When the number of nodes in the target circular linked list is empty, the thread and timer are closed.
[0103] In practical applications, a fault reporting system can also be connected to record relevant information in the above execution process, so that developers can quickly locate online problems based on the information and find solutions.
[0104] The following introduces the network request processing method of the present application in combination with a specific application scenario. Applied to a terminal, please refer toFigure 9 , Figure 9 shows the flowchart of the network request processing method in this embodiment.
[0105] S1: Start the application.
[0106] Specifically, the application sends a network request to the server.
[0107] S2: Monitor whether a network request failure occurs in the network request of the application. If so, execute step S5.
[0108] S3: In response to the start of the application, initialize the control tool class.
[0109] Specifically, the control tool class can be the NetControlCenter class.
[0110] S4: Create a target circular linked list based on the method defined by the control tool class.
[0111] Specifically, call this method to create a target circular linked list. The created target circular linked list can be a double - linked target circular linked list. Allocate separate memory spaces for each node. Each node includes a data field for storing target request data and a pointer field for storing forward and backward pointers.
[0112] S5: In response to the network request failure, create a request data model object in the target circular linked list.
[0113] Specifically, create a node in the target circular linked list, and the node is a request data model object.
[0114] S6: Write the request parameter information of the network request into the request data model object to generate target request data.
[0115] Specifically, in response to the network request failure, perform DNS resolution on the destination domain name in the request parameter information to obtain the destination IP address, and generate a destination IP field. Also, convert other request parameter information into request parameter fields corresponding to the request data model object, and then write the destination IP field and other request parameter fields into the target field positions in the request data model object.
[0116] S7: Monitor whether the number of nodes n in the target circular linked list is greater than zero. If so, execute step S8. If not, execute step S7.
[0117] S8: Start a thread and a timer.
[0118] S9: Traverse and obtain the target request data of each node in the target circular linked list based on the thread and the timer.
[0119] Specifically, based on the data acquisition time interval set by the timer, the target request data in the target circular linked list is sequentially acquired using a thread.
[0120] S10: Determine whether the destination IP field in the target request data is empty. If it is, execute step S13; if not, execute step S11.
[0121] Specifically, the destination IP field can be stored in the DNSIP field.
[0122] S11: Execute a ping command on the destination IP address corresponding to the destination IP field based on the ICMP protocol.
[0123] S12: Determine whether the destination IP is reachable based on the ping command result. If it is, execute step S13; if not, execute step S7.
[0124] S13: Retrieve the target request data from the target circular linked list, construct and send a target network request.
[0125] Specifically, that is, retrieve the request data model object from the target circular linked list.
[0126] Specifically, if the DNSIP field is not empty, first execute a ping command operation on the destination IP address based on the ICMP protocol. When the value of the returned type field is 0, it means the host is reachable. Then retrieve the corresponding target request data from the target circular linked list, generate a corresponding target network request based on the target request data, and send the request based on the destination URL address corresponding to the URL field for network retry. If it is found that the DNSIP field is empty, directly retrieve the corresponding target request data to generate a target network request and attempt to send the request based on the destination URL address corresponding to the URL field for network retry.
[0127] S14: Monitor whether the target network request is successfully called back. If it is, execute step S15; if not, execute step S9.
[0128] S15: Delete the node corresponding to the target request data from the target circular linked list.
[0129] The embodiment of the present application also provides a network request processing device 700, which is applied to a terminal, as Figure 10 shown, Figure 10 shows a schematic structural diagram of a network request processing device provided by the embodiment of the present application. The device may include:
[0130] A response status determination module 10: used to obtain the first response status of a network request initiated by an application program;
[0131] Request data generation module 20: If the first response status is response failure, it is used to generate corresponding target request data in the target circular linked list based on the request parameter information of the network request;
[0132] Network connectivity detection module 30: It is used to detect the network connectivity status according to the preset network layer protocol and the target request data stored in the target circular linked list;
[0133] Network request retry module 40: It is used to resend the target network request corresponding to the target request data when network connectivity is detected.
[0134] In some embodiments, the request data generation module 20 may include:
[0135] Model object generation unit: It is used to generate a request data model object in the target circular linked list based on a predefined model class;
[0136] Request parameter addition unit: It is used to add the request parameter information to the request data model object to obtain the target request data.
[0137] In some embodiments, the request parameter addition unit may include:
[0138] Format conversion subunit: It is used to perform format conversion processing on the request parameter information to obtain the corresponding request parameter fields;
[0139] Parameter field addition subunit: It is used to add the request parameter fields to the target field position in the request data model object to obtain the target request data.
[0140] In some embodiments, the target request data includes the destination IP address; the network connectivity detection module 30 may include:
[0141] Destination IP acquisition unit: It is used to acquire the destination IP addresses of the respective target request data stored in the target circular linked list;
[0142] Network connectivity detection unit: It is used to cyclically detect the network connectivity status corresponding to each target request data according to the preset network layer protocol and the destination IP address, based on the data storage order in the target circular linked list.
[0143] In some embodiments, the network connectivity detection unit may include:
[0144] Echo request generation subunit: It is used to generate a packet echo request corresponding to each target request data according to the destination IP address and the preset network layer protocol;
[0145] Echo request sending subunit: It is used to cyclically send the packet echo requests corresponding to each target request data based on the data storage order in the target circular linked list.
[0146] A connectivity status determination subunit: configured to determine the network connectivity status corresponding to each target request data according to the response information of the message return request.
[0147] In some embodiments, the network request retry module 40 may include:
[0148] A request data reading unit: configured to, if it is detected that the network connectivity status corresponding to the target request data is connected, take out the corresponding target request data from the target circular linked list;
[0149] A network request generating unit: configured to generate a corresponding target network request according to the target request data and send the target network request.
[0150] In some embodiments, the request data reading unit is further configured to: before detecting the network connectivity status according to the target request data stored in the target circular linked list, if any target request data in the target circular linked list does not include a destination IP address, take out the corresponding target request data from the target circular linked list;
[0151] The network request generating unit is further configured to: generate a corresponding target network request according to the target request data and send the target network request.
[0152] In some embodiments, the apparatus may further include:
[0153] A response status monitoring module: configured to monitor the second response status of the target network request after generating a corresponding target network request according to the target request data and sending the target network request;
[0154] A request data deletion module: configured to delete the corresponding target request data from the target circular linked list when the second response status is a successful response.
[0155] The above apparatus embodiment and method embodiment are based on the same implementation manner.
[0156] An embodiment of the present application provides a network request processing device, which includes a processor and a memory. At least one instruction or at least one program segment is stored in the memory, and the at least one instruction or the at least one program segment is loaded and executed by the processor to implement the network request processing method provided in the above method embodiment.
[0157] An embodiment of the present application further provides a terminal, which includes a processor and a memory. At least one instruction or at least one program segment is stored in the memory, and the at least one instruction or the at least one program segment is loaded and executed by the processor to implement the above network request processing method.
[0158] The memory can be used to store software programs and modules. By running the software programs and modules stored in the memory, the processor can execute various functional applications and data processing. The memory mainly includes a program storage area and a data storage area. Among them, the program storage area can store the operating system, application programs required for functions, etc.; the data storage area can store data created according to the use of the device, etc. In addition, the memory can include high-speed random access memory and can also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other volatile solid-state storage devices. Accordingly, the memory can also include a memory controller to provide the processor with access to the memory.
[0159] The method embodiments provided in the embodiments of the present application can be executed on a mobile terminal, a computer terminal, a server, or similar electronic devices. Figure 11 It is a hardware structure block diagram of an electronic device for a network request processing method provided in the embodiments of the present application. As Figure 11 shown, the electronic device 800 can vary greatly due to configuration or performance differences and can include one or more central processing units (CPUs) 810 (the processor 810 can include, but is not limited to, processing devices such as a microprocessor MCU or a programmable logic device FPGA), a memory 830 for storing data, and one or more storage media 820 (such as one or more mass storage devices) for storing application programs 823 or data 822. Among them, the memory 830 and the storage media 820 can be short-term storage or persistent storage. The programs stored in the storage media 820 can include one or more modules, and each module can include a series of instruction operations on the electronic device. Further, the central processor 810 can be configured to communicate with the storage media 820 and execute a series of instruction operations in the storage media 820 on the electronic device 800. The electronic device 800 can also include one or more power supplies 860, one or more wired or wireless network interfaces 850, one or more input / output interfaces 840, and / or one or more operating systems 821, such as Windows Server TM , Mac OS X TM , Unix TM , LinuxTM, FreeBSDTM, and so on.
[0160] The input / output interface 840 can be used to receive or transmit data via a network. Specific examples of the above-mentioned network may include a wireless network provided by a communication provider of the electronic device 800. In one example, the input / output interface 840 includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the input / output interface 840 can be a Radio Frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0161] Those of ordinary skill in the art can understand that Figure 11 the structure shown is only illustrative and does not limit the structure of the above-mentioned electronic device. For example, the server 800 may further include more or fewer components than those shown in Figure 11 or have a different configuration from that shown in Figure 11
[0162] An embodiment of the present application further provides a computer-readable storage medium. The storage medium can be disposed in the server to store at least one instruction or at least one segment of a program related to a network request processing method in the method embodiment. The at least one instruction or the at least one segment of the program is loaded and executed by the processor to implement the network request processing method provided in the above method embodiment.
[0163] Optionally, in this embodiment, the above storage medium may be located in at least one of multiple network servers in a computer network. Optionally, in this embodiment, the above storage medium may include, but is not limited to: USB flash drives, read-only memories (ROM, Read-Only Memory), random access memories (RAM, Random Access Memory), mobile hard disks, magnetic disks, or optical discs, and other media that can store program codes.
[0164] According to one aspect of the present application, there is provided a computer program product or a computer program. The computer program product or the computer program includes computer instructions, and the computer instructions are stored in a computer-readable storage medium. The processor of the computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the methods provided in the above various optional implementation manners.
[0165] As can be seen from the embodiments of the network request processing method, apparatus, device, terminal, electronic device or storage medium provided by the present application above, the present application obtains the first response status of a network request initiated by an application program; if the first response status is a response failure, corresponding target request data is generated in a target circular linked list based on the request parameter information of the network request; the network connectivity status is detected according to a preset network layer protocol and the target request data stored in the target circular linked list; and in the case where network connectivity is detected, a target network request corresponding to the target request data is sent. Before performing network retry, the terminal first determines whether the network is connected based on the network layer protocol, and then executes network request retry after detecting connectivity, which can avoid frequent sending of the same network request during the retry process, improve the success rate of the secondary request, reduce traffic consumption and the pressure on the server system, and store the target request data based on the circular linked list, enabling the corresponding network detection and network retry to be automatically executed in a loop without additional monitoring and loop triggering operations, effectively improving the data processing efficiency.
[0166] It should be noted that: the above sequence of the embodiments of the present application is only for description and does not represent the advantages or disadvantages of the embodiments. And the above specific embodiments of the present application have been described. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims may be performed in a different order than in the embodiments and still achieve the desired result. Additionally, the processes depicted in the drawings do not necessarily require the specific order or sequential order shown to achieve the desired result. In certain embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0167] The various embodiments in the present application are all described in a progressive manner. The same or similar parts among the various embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the embodiments of the apparatus, device, and storage medium, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments.
[0168] Those of ordinary skill in the art can understand that all or part of the steps to implement the above embodiments can be completed by hardware, or can be completed by a program instructing relevant hardware. The program can be stored in a computer-readable storage medium, and the above-mentioned storage medium can be a read-only memory, a disk, an optical disc, etc.
[0169] The above are only the preferred embodiments of the present application and are not intended to limit the present application. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims
1. A network request processing method, applied to a terminal, characterized in that, The method includes: Obtaining a first response status of a network request initiated by an application; If the first response status is a response failure, generating corresponding target request data in a target circular linked list based on the request parameter information of the network request; each node in the target circular linked list corresponds to a network request; Detecting a network connectivity status according to a preset network layer protocol and the target request data stored in the target circular linked list; Resending a target network request corresponding to the target request data when network connectivity is detected.
2. The method according to claim 1, wherein The step of, if the first response status is a response failure, generating corresponding target request data in a target circular linked list based on the request parameter information of the network request includes: Generating a request data model object in the target circular linked list based on a predefined model class; Adding the request parameter information to the request data model object to obtain the target request data.
3. The method according to claim 2, characterized in that, The step of adding the request parameter information to the request data model object to obtain the target request data includes: Performing format conversion processing on the request parameter information to obtain corresponding request parameter fields; Adding the request parameter fields to a target field position in the request data model object to obtain the target request data.
4. The method according to any one of claims 1 to 3, characterized in that, The target request data includes a destination IP address; the step of detecting a network connectivity status according to a preset network layer protocol and the target request data stored in the target circular linked list includes: Obtaining the destination IP addresses of the respective target request data stored in the target circular linked list; According to the preset network layer protocol and the destination IP address, and based on the data storage order in the target circular linked list, circularly detecting the network connectivity status corresponding to each of the target request data.
5. The method according to claim 4, wherein The step of, according to the preset network layer protocol and the destination IP address, and based on the data storage order in the target circular linked list, circularly detecting the network connectivity status corresponding to each of the target request data includes: Generating a message echo request corresponding to each of the target request data according to the preset network layer protocol and the destination IP address; Circularly sending the message echo requests corresponding to each of the target request data based on the data storage order in the target circular linked list; Determining the network connectivity status corresponding to each of the target request data according to the response information of the message echo request.
6. The method according to claim 1, wherein The step of, when network connectivity is detected, resending a target network request corresponding to the target request data includes: If the network connectivity status corresponding to any target request data is detected as connected, taking out the corresponding target request data from the target circular linked list; Generating a corresponding target network request according to the target request data and sending the target network request.
7. The method according to any one of claims 1 to 3, characterized in that, Before the step of detecting a network connectivity status according to a preset network layer protocol and the target request data stored in the target circular linked list, the method further includes: If any target request data in the target circular linked list does not include a destination IP address, taking out the corresponding target request data from the target circular linked list; Generate a corresponding target network request according to the target request data, and send the target network request.
8. The method according to claim 1, characterized in that, After generating a corresponding target network request according to the target request data and sending the target network request, the method further includes: Monitor the second response status of the target network request; When the second response status is a successful response, delete the corresponding target request data from the target circular linked list.
9. A network request processing device, characterized in that, The device includes: A response status determination module: used to obtain the first response status of a network request initiated by an application; A request data generation module: used to generate corresponding target request data in a target circular linked list based on the request parameter information of the network request if the first response status is a failed response; each node in the target circular linked list corresponds to a network request; A network connectivity detection module: used to detect the network connectivity status of the target request data stored in the target circular linked list according to a preset network layer protocol; A network request retry module: used to resend the target network request corresponding to the target request data when network connectivity is detected.
10. The device according to claim 9, characterized in that, The request data generation module includes: A model object generation unit: used to generate a request data model object in the target circular linked list based on a predefined model class; A request parameter addition unit: used to add the request parameter information to the request data model object to obtain the target request data.
11. The device according to claim 10, wherein The request parameter addition unit includes: A format conversion subunit: used to perform format conversion processing on the request parameter information to obtain corresponding request parameter fields; A parameter field addition subunit: used to add the request parameter fields to the target field position in the request data model object to obtain the target request data.
12. The device according to any one of claims 9-11, characterized in that The target request data includes a destination IP address; The network connectivity detection module includes: A destination IP acquisition unit: used to acquire the destination IP addresses of the respective target request data stored in the target circular linked list; A network connectivity detection unit: used to cyclically detect the network connectivity status corresponding to each of the target request data according to the preset network layer protocol and the destination IP address, based on the data storage order in the target circular linked list.
13. The device according to claim 12, characterized in that, The network connectivity detection unit includes: A loopback request generation subunit: used to generate a message loopback request corresponding to each of the target request data according to the preset network layer protocol and the destination IP address; A loopback request sending subunit: used to cyclically send the message loopback requests corresponding to each of the target request data based on the data storage order in the target circular linked list; A connectivity status determination subunit: used to determine the network connectivity status corresponding to each of the target request data according to the response information of the message loopback request.
14. The device according to claim 9, characterized in that, The network request retry module includes: A request data reading unit: used to take out the corresponding target request data from the target circular linked list if the network connectivity status corresponding to any target request data is detected as connected; A network request generation unit: used to generate a corresponding target network request according to the target request data and send the target network request.
15. The device according to claim 14, characterized in that, The request data reading unit is further configured to: Before detecting the network connectivity status according to the preset network layer protocol and the target request data stored in the target circular linked list, if any target request data in the target circular linked list does not include the destination IP address, take out the corresponding target request data from the target circular linked list; The network request generation unit is further configured to: generate a corresponding target network request according to the target request data, and send the target network request.
16. The device according to claim 9, wherein The device further includes: A response status monitoring module: configured to monitor the second response status of the target network request after generating a corresponding target network request according to the target request data and sending the target network request; A request data deletion module: configured to delete the corresponding target request data from the target circular linked list when the second response status is a successful response.
17. A computer-readable storage medium, characterized in that, At least one instruction or at least one program segment is stored in the storage medium, and the at least one instruction or the at least one program segment is loaded and executed by a processor to implement the network request processing method according to any one of claims 1-8.
18. A network request processing device, characterized in that, The device includes a processor and a memory. The memory stores at least one instruction or at least one program segment, and the at least one instruction or the at least one program segment is loaded and executed by the processor to implement the network request processing method according to any one of claims 1-8.
19. A terminal, characterized in that, The terminal includes a processor and a memory. The memory stores at least one instruction or at least one program segment, and the at least one instruction or the at least one program segment is loaded and executed by the processor to implement the network request processing method according to any one of claims 1-8.
20. A computer program product, characterized in that, The computer program product includes computer instructions, the computer instructions are stored in a computer-readable storage medium, a processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the network request processing method according to any one of claims 1-8.
Citation Information
Patent Citations
Network connectivity diagnosis method and device, terminal and storage medium
CN111314181A
Method and device for accessing data
CN111835857A