Abnormal request capture method, device, electronic device and storage medium
By introducing custom exception listening functions into the HTTP request program of the client and adding them to the target API function, the problem of difficulty in fully capturing exception HTTP requests in the existing technology is solved, and comprehensive exception capture of web applications is achieved, reducing the burden on developers and reducing development costs.
Patent Information
- Application Number
- CN202210904876.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-29
- Publication Date
- 2025-05-06
- Estimated Expiration
- 2042-07-29
AI Technical Summary
The prior art is difficult to capture exception HTTP requests in web applications in a comprehensive and timely manner, which causes developers to write additional exception capture code, which consumes time and resources.
By introducing a custom exception listening function into the client's HTTP request program and adding it directly to the target API function required to generate HTTP requests, ensuring that the developer can catch exception HTTP requests no matter which API they use.
Implement exception capture of all HTTP requests in web applications, reduces the development burden of developers, and reduces the development cost of web applications.
Smart Images

Figure CN115378925B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of Internet technology, and in particular to an abnormal request capturing method, device, electronic device and storage medium. Background Art
[0002] With the rapid development of Internet technology, the interaction between clients and servers through the HTTP protocol is very important, which is conducive to the dynamic content of Web applications (applications accessed through the World Wide Web). The Web community also provides many APIs for developers to use. When developing programs, developers can choose one or more APIs to handle HTTP requests according to their preferences.
[0003] At present, various original APIs provided in the Web community have their own corresponding exception catching mechanisms. If developers want to implement the exception catching function, they can add corresponding exception catching codes in the developed programs according to the APIs they use. However, with this solution, only some HTTP requests to which the developer has added the exception catching code can be caught, and it cannot guarantee that all HTTP requests of the Web application can be caught. In addition, this solution requires each developer to write additional exception catching code in addition to the code for implementing a certain function of the application during the development process, which consumes the developer's time, energy and other resources. Summary of the invention
[0004] The embodiments of the present invention provide an abnormal request capturing method, device, electronic device and storage medium, which can comprehensively and timely capture abnormal HTTP requests in Web applications, reduce the development burden of developers, and reduce the development cost of Web applications.
[0005] An embodiment of the present invention provides a method for capturing abnormal requests, which is applied to a client. The method includes:
[0006] Based on the HTTP request triggering event of the client, determining an HTTP request program that responds to the HTTP request triggering event, wherein the HTTP request program is at least used to generate an HTTP request;
[0007] Determine a target API function that needs to be called when the HTTP request program generates an HTTP request, wherein the target API function includes a custom exception monitoring function, and the custom exception monitoring function is customized by a development side of the client;
[0008] Based on the HTTP request program, the target API function is called to generate an HTTP request and sent to the server, and the custom exception monitoring function in the target API function is called;
[0009] Monitoring abnormal events based on the server response information of the HTTP request through the custom abnormal monitoring function;
[0010] If an abnormal event is detected, obtain the HTTP request log corresponding to the abnormal event and report it.
[0011] Accordingly, an embodiment of the present invention further provides an abnormal request capturing device, comprising:
[0012] A program determining unit, configured to determine, based on the HTTP request triggering event of the client, an HTTP request program that responds to the HTTP request triggering event, wherein the HTTP request program is at least configured to generate an HTTP request;
[0013] A function determination unit, used for determining a target API function to be called when the HTTP request program generates an HTTP request, wherein the target API function includes a custom exception monitoring function, and the custom exception monitoring function is customized by a development side of the client;
[0014] A function calling unit, configured to call the target API function based on the HTTP request program to generate an HTTP request and send the request to the server, and to call the custom exception monitoring function in the target API function;
[0015] An event monitoring unit, used to monitor abnormal events based on the server response information of the HTTP request through the custom abnormal monitoring function;
[0016] The log reporting unit is used to obtain and report the HTTP request log corresponding to the abnormal event if an abnormal event is monitored.
[0017] Optionally, the abnormal request capture device provided by the embodiment of the present invention further includes a queue creation unit, which is used to create an abnormal request log queue, wherein the abnormal request log queue is used to store logs corresponding to abnormal HTTP requests;
[0018] The log reporting unit is used to obtain the HTTP request log corresponding to the abnormal event and store the HTTP request log in the abnormal request log queue;
[0019] The HTTP request log in the abnormal request log queue is reported.
[0020] Optionally, the target API function includes an XMLHttpRequest function, and the function calling unit is used to call the XMLHttpRequest function to generate an HTTP request based on the request object corresponding to the HTTP request program;
[0021] Send the HTTP request to the server, and call the custom exception monitoring function in the XMLHttpRequest function;
[0022] The event monitoring unit is used to obtain the server response message corresponding to the request object through the custom exception monitoring function;
[0023] The server response message is parsed to monitor abnormal events.
[0024] Optionally, the XMLHttpRequest function includes a custom initialization function, and the abnormal request capture device provided by the embodiment of the present invention further includes an object initialization unit, which is used to create a request object corresponding to the HTTP request program based on the HTTP request program;
[0025] Calling the custom initialization function to initialize the request object;
[0026] By means of the custom initialization function, the interface address in the custom initialization function is added to the request object;
[0027] The log reporting unit is used to obtain the interface address in the request object and write the HTTP request log corresponding to the abnormal event if an abnormal event is monitored;
[0028] Obtain the HTTP request log and report it.
[0029] Optionally, the target API function includes a Fetch function, and the function calling unit is used to call the Fetch function based on the HTTP request program to generate an HTTP request;
[0030] Send an HTTP request to the server and call the custom exception listening function in the Fetch function;
[0031] The event monitoring unit is used to parse the server response object corresponding to the received HTTP request through the custom exception monitoring function to obtain the HTTP status code in the server response object;
[0032] Based on the HTTP status code, abnormal events are monitored.
[0033] Optionally, the abnormal request capture device provided by the embodiment of the present invention further includes a function generation unit, which is used to determine a target reporting platform for the HTTP request log and obtain a log reporting API of the target reporting platform;
[0034] Based on the log reporting API, a log reporting function is generated, wherein the log reporting function includes a log reporting sub-function and a reporting exception capture sub-function;
[0035] The log reporting unit is used to report the abnormal request log in the abnormal request log queue through the log reporting sub-function;
[0036] The abnormal request capture device provided by the embodiment of the present invention further includes a reporting stopping unit, which is used to record the number of abnormalities of reporting abnormalities when reporting through the log reporting sub-function based on the reporting abnormality capture sub-function;
[0037] If the number of exceptions is not less than a preset threshold number of exceptions, stop reporting the HTTP request log.
[0038] Optionally, the abnormal request capture device provided by the embodiment of the present invention further includes a function generation unit, which is used to determine a target reporting platform for the HTTP request log and obtain a log reporting API of the target reporting platform;
[0039] Based on the log reporting API, a log reporting function is generated, wherein the log reporting function includes a running idle detection function and a log reporting sub-function;
[0040] Add the log reporting function to the client program;
[0041] The log reporting unit is used to detect the working status of the client by running the idle detection function;
[0042] When the working state of the client is an idle state, the HTTP request log in the abnormal request log queue is reported through the log reporting sub-function.
[0043] Correspondingly, an embodiment of the present invention further provides an electronic device, comprising a memory and a processor; the memory stores an application, and the processor is used to run the application in the memory to execute the steps in any one of the abnormal request capture methods provided in the embodiments of the present invention.
[0044] Correspondingly, an embodiment of the present invention further provides a computer-readable storage medium, which stores a plurality of instructions, and the instructions are suitable for a processor to load to execute the steps in any one of the abnormal request capture methods provided in the embodiments of the present invention.
[0045] In addition, an embodiment of the present invention further provides a computer program product, including a computer program or instructions, which, when executed by a processor, implements the steps in any one of the abnormal request capture methods provided in the embodiments of the present invention.
[0046] By adopting the scheme of the embodiment of the present invention, an HTTP request program that responds to the HTTP request triggering event can be determined based on the HTTP request triggering event of the client, the HTTP request program is at least used to generate an HTTP request, a target API function that needs to be called when the HTTP request program generates the HTTP request is determined, the target API function includes a custom exception monitoring function, the custom exception monitoring function is customized by the development side of the client, the target API function is called based on the HTTP request program to generate an HTTP request and send it to the server, and the custom exception monitoring function in the target API function is called, and an exception event is handled based on the server response information of the HTTP request through the custom exception monitoring function. If an abnormal event is monitored, the HTTP request log corresponding to the abnormal event is obtained and reported; because in the embodiment of the present invention, the target API function to be called when generating the HTTP request is modified, and the custom exception monitoring function is directly added to the target API function that cannot be bypassed when generating the request, therefore, no matter which API the developer uses, it is necessary to call the target API function and then call the custom exception monitoring function, which can comprehensively and timely capture abnormal HTTP requests in the Web application, and the custom exception monitoring function is directly modified into the target API function, without the developer having to write the relevant code for exception capture by himself, which can reduce the development burden of the developer and reduce the development cost of the Web application. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0048] Figure 1 It is a scenario schematic diagram of the abnormal request capturing method provided by an embodiment of the present invention;
[0049] Figure 2 is a flow chart of an abnormal request capturing method provided by an embodiment of the present invention;
[0050] Figure 3 It is a schematic diagram of the HTTP request log reporting process provided by an embodiment of the present invention;
[0051] Figure 4 is another flow chart of the abnormal request capturing method provided by an embodiment of the present invention;
[0052] Figure 5 It is a structural diagram of an abnormal request capturing device provided by an embodiment of the present invention;
[0053] Figure 6 is another structural schematic diagram of the abnormal request capturing device provided by an embodiment of the present invention;
[0054] Figure 7 It is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0055] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0056] The embodiments of the present invention provide an abnormal request capture method, device, electronic device and computer-readable storage medium. Specifically, the embodiments of the present invention provide an abnormal request capture method applicable to an abnormal request capture device, and the abnormal request capture device can be integrated in an electronic device.
[0057] The electronic device can be a terminal or other device, including but not limited to a mobile terminal and a fixed terminal. For example, a mobile terminal includes but is not limited to a smart phone, a smart watch, a tablet computer, a laptop computer, a smart car-mounted terminal, etc., wherein a fixed terminal includes but is not limited to a desktop computer, a smart TV, etc.
[0058] The electronic device can also be a device such as a server. The server can be an independent physical server, a server cluster or a distributed system composed of multiple physical servers, or a cloud server that provides 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), as well as big data and artificial intelligence platforms, but is not limited to these.
[0059] The abnormal request capturing method of the embodiment of the present invention may be implemented by a server, or may be implemented by a terminal and a server together.
[0060] The method is described below by taking the example of a terminal and a server jointly implementing the abnormal request capture method.
[0061] like Figure 1As shown, the abnormal request capture system provided by an embodiment of the present invention includes a terminal 10 and a server 20, etc.; the terminal 10 and the server 20 are connected via a network, such as a wired or wireless network connection, etc., wherein the server 20 can exist as an electronic device that responds to the HTTP request sent by the terminal 10.
[0062] Among them, the terminal 10 can be used to determine the HTTP request program that responds to the HTTP request trigger event based on the HTTP request trigger event of the client, the HTTP request program is at least used to generate an HTTP request, determine the target API function that needs to be called when the HTTP request program generates the HTTP request, the target API function includes a custom exception monitoring function, the custom exception monitoring function is customized by the development side of the client, based on the HTTP request program calling the target API function to generate an HTTP request and send it to the server, and call the custom exception monitoring function in the target API function.
[0063] The server 20 may receive the HTTP request sent by the terminal 10 , and return server response information to the terminal 10 based on the HTTP request.
[0064] The terminal 10 can monitor abnormal events based on the server response information of the HTTP request through a custom abnormal monitoring function. If an abnormal event is monitored, the HTTP request log corresponding to the abnormal event is obtained and reported.
[0065] It is understandable that, in some embodiments, the step of capturing abnormal requests performed by the terminal 10 may also be performed by the server 20, which is not limited in this embodiment of the present invention.
[0066] It should be noted that the description order of the following embodiments is not intended to limit the preferred order of the embodiments.
[0067] The embodiment of the present invention will be described from the perspective of an abnormal request capturing device, which may be integrated in a server or a terminal.
[0068] like Figure 2 As shown, the specific process of the abnormal request capture method of this embodiment can be as follows:
[0069] 201. Based on an HTTP request triggering event of a client, determine an HTTP request program that responds to the HTTP request triggering event, where the HTTP request program is at least used to generate an HTTP request.
[0070] In the embodiment of the present invention, the client refers to a program corresponding to the server and providing local services to the client. For example, the client can be a browser client, an email client, a game client, an instant messaging client, or the like.
[0071] Specifically, the client may be in the form of a web page, or may be software running in an electronic device such as a mobile terminal, which is not limited in the embodiment of the present invention.
[0072] The HTTP request triggering event refers to an event that triggers the client to send an HTTP request to the server. For example, the HTTP request triggering event may be an operation performed by a user on a control in the client, such as single-clicking or double-clicking a control. Alternatively, the HTTP request triggering event may be automatically triggered by the client, such as a web client sending an HTTP request every 3 minutes to obtain data to update the page, etc.
[0073] The HTTP request program is a program that can be used to generate HTTP requests. It is understandable that the HTTP request program can also have functions such as sending HTTP requests, instructing the server to return certain data, and / or instructing the server to respond in a specific form. The embodiment of the present invention does not limit other functions of the HTTP request program, and developers can set them according to actual applications or development requirements.
[0074] Specifically, an HTTP request may be a request message from a client to a server, and a client may request required resources from a server by sending an HTTP request. The format of an HTTP request and the information contained in the HTTP request may be set by the developer.
[0075] 202. Determine a target API function that needs to be called when the HTTP request program generates an HTTP request. The target API function includes a custom exception monitoring function. The custom exception monitoring function is customized by the development side of the client.
[0076] It is understandable that in the related art, when developing a client, the developer can use a variety of existing API functions to enable the client to have the functions of generating and sending requests.
[0077] For example, the relevant technology can use API functions such as XMLHttpRequest, Fetch, Axios, and umi-request. Among them, API functions such as Axios and umi-request are actually encapsulations of XMLHttpRequest or Fetch. That is to say, these API functions need to implement request-related functions, and essentially use XMLHttpRequest or Fetch functions.
[0078] In the embodiment of the present invention, the target API function may refer to an XMLHttpRequest function or a Fetch function. Specifically, the step of "determining the target API function to be called when the HTTP request program generates an HTTP request" may specifically include:
[0079] Determine whether the function that needs to be called when the HTTP request program generates an HTTP request belongs to the XMLHttpRequest function or the Fetch function;
[0080] If the function to be called when generating an HTTP request belongs to the XMLHttpRequest function, the XMLHttpRequest function is used as the target API function;
[0081] If the function to be called when generating an HTTP request is a Fetch function, the Fetch function is used as the target API function.
[0082] Among them, to determine whether the function that needs to be called when the HTTP request program generates an HTTP request belongs to the XMLHttpRequest function or the Fetch function, the program code of the HTTP request program can be parsed, for example, the method name called when generating or sending the request is parsed to determine which function the called method function belongs to, or the format of the information required to be returned by the server in the HTTP request program can be parsed.
[0083] For example, in an HTTP request program that uses the XMLHttpRequest function to generate an HTTP request, statements such as xhr.readyState and / or xhr.response can be used to instruct the server to return response information of the corresponding type. Based on these statements, it can be determined that the HTTP request program implements functions such as generating and sending requests based on the XMLHttpRequest function.
[0084] For another example, in an HTTP request program that uses a Fetch function to generate an HTTP request, a fetch() method is generally required. According to the fetch() statement, it can be determined that the HTTP request program implements functions such as generating and sending requests based on the Fetch function.
[0085] It should be noted that the XMLHttpRequest function or Fetch function mentioned in the embodiment of the present invention is not a native XMLHttpRequest function or Fetch function, but a function modified on the basis of the native XMLHttpRequest function or Fetch function.
[0086] Specifically, the target API function (ie, the modified XMLHttpRequest function or Fetch function) of the embodiment of the present invention includes a custom exception monitoring function. By using the custom exception monitoring function, it is possible to monitor abnormal HTTP requests.
[0087] The "customization" of the custom exception monitoring function refers to the implementation logic of the exception monitoring function designed and implemented by the client development side. For example, if the target API function is an XMLHttpRequest function, the custom exception monitoring function of the embodiment of the present invention may include specific implementation codes for abnormal events such as timeout events, and in these custom exception monitoring functions, developers can set the judgment conditions for abnormal events, such as the timeout time corresponding to the timeout event, etc.
[0088] 203. Based on the HTTP request program, the target API function is called to generate an HTTP request and sent to the server, and a custom exception monitoring function in the target API function is called.
[0089] In the related art, some API functions have their own exception monitoring functions, but these exception monitoring functions only correspond to a single API function. For example, if the developer uses the Axios function, the code of the exception monitoring function can only monitor the exception requests generated by the Axios function.
[0090] In addition, the exception monitoring function must be manually written into the client program by the developer. If the developer does not write it, the monitoring function cannot be implemented. For example, for controls A and B, if you want to implement comprehensive monitoring of the requests of controls A and B, the developer needs to write the calling code of the exception monitoring function in the function code of controls A and B respectively. If the developer forgets to write the calling code of the exception monitoring function corresponding to control A, the request corresponding to control A cannot be monitored.
[0091] It is understandable that the target API function can actually be regarded as a function set, which may include multiple different functions. In the embodiment of the present invention, the custom exception monitoring function is logically bound to the functions related to the generation and sending of requests in the target API function, so that once the HTTP request program starts running, it is necessary to call the functions related to the generation and sending of requests in the target API function. Further, since the custom exception monitoring function has a logical binding relationship with these functions, the custom exception monitoring function will also be called.
[0092] Therefore, by modifying the target API function in the embodiment of the present invention, comprehensive and timely abnormal request monitoring can be achieved. No matter which API function the developer uses, the developer does not need to write a call code for the abnormal monitoring function separately, and the request interaction process between the client and the server can be abnormally captured.
[0093] In some optional embodiments, the target API function may include an XMLHttpRequest function, and the step of “calling the target API function based on the HTTP request program to generate an HTTP request and sending it to the server, and calling a custom exception listening function in the target API function” may specifically include:
[0094] Based on the request object corresponding to the HTTP request program, call the XMLHttpRequest function to generate an HTTP request;
[0095] Send an HTTP request to the server and call the custom exception listening function in the XMLHttpRequest function.
[0096] The request object refers to an object created during the operation of an HTTP request program written based on the XMLHttpRequest function. In the implementation logic of the XMLHttpRequest function, if you want to implement the interaction between the client and the server, you need to rely on the XMLHttpRequest (XHR) object.
[0097] Specifically, the HTTP request program can generate and send HTTP requests based on the open() function and the send() function in the XMLHttpRequest function. Specifically, the open() function can initialize the request parameters of the HTTP request for later use by the send() method. The send() function can send an HTTP request.
[0098] In some examples, a custom exception listening function may be bound to a send() function, and developers may limit the execution of the custom exception listening function to the execution of the send() function during the process of modifying the XMLHttpRequest function.
[0099] Alternatively, developers can write a custom exception monitoring function into the send() function, making the custom exception monitoring function a part of the send() function. Through this modification of the send() function, it is possible to monitor abnormal events such as error events and timeout events when the client sends an HTTP request to the server.
[0100] Optionally, the XMLHttpRequest function may include a custom initialization function. Before the step of "based on the request object corresponding to the HTTP request program, calling the XMLHttpRequest function to generate an HTTP request", the abnormal request capture method provided by the embodiment of the present invention may further include:
[0101] Based on the HTTP request program, create a request object corresponding to the HTTP request program;
[0102] Call the custom initialization function to initialize the request object;
[0103] Through the custom initialization function, add the interface address in the custom initialization function to the request object.
[0104] It is understandable that during one operation of the client, an object may be created only once, and during subsequent operations of the client, if the same request needs to be sent again, it may be implemented directly based on the created object.
[0105] The custom initialization function is a function customized by the development side of the client, and the custom initialization function can be used to initialize the HTTP request.
[0106] In an HTTP request program written based on the XMLHttpRequest function, the HTTP request can be initialized through the open() function. In an embodiment of the present invention, the open() function in the native XMLHttpRequest function can be modified so that the interface address (i.e., URL) recorded in the open() function will not be lost during the request process.
[0107] Correspondingly, the step "If an abnormal event is monitored, obtain the HTTP request log corresponding to the abnormal event and report it" includes:
[0108] If an abnormal event is detected, obtain the interface address in the request object and write it into the HTTP request log corresponding to the abnormal event;
[0109] Obtain HTTP request logs and report them.
[0110] Specifically, developers can add the statement this.ajaxUrl = url in the open() function. Even if the interface address is lost during the three-way handshake between the client and the server, the interface address can be obtained through this statement and written into the HTTP request log.
[0111] In some other optional embodiments, the target API function may include a Fetch function, and the step of "calling the target API function based on the HTTP request program to generate an HTTP request and sending it to the server, and calling a custom exception listening function in the target API function" may specifically include:
[0112] Based on the HTTP request program, call the Fetch function to generate an HTTP request;
[0113] Send an HTTP request to the server and call the custom exception listening function in the Fetch function;
[0114] Specifically, the developer can rewrite the fetch() function in the Fetch function and add a custom exception monitoring function that can monitor the server's Response to the function.
[0115] After the client sends an HTTP request, the custom exception listening function can monitor the server response information returned by the server.
[0116] 204. By customizing the exception monitoring function, the abnormal event is monitored based on the server response information of the HTTP request.
[0117] The server response information is the response information received after the HTTP request is sent to the server. It can be understood that the server response information is generally returned to the client by the server that receives the HTTP request.
[0118] In some special cases, the server response information may not be returned by the server to the client. For example, when the user's network has a connection problem, the client cannot successfully send an HTTP request to the server. At this time, the client can also obtain the server response information, which is generated by the client because it cannot successfully send a request to the server.
[0119] Specifically, when the target API function includes an XMLHttpRequest function, the step of "monitoring abnormal events based on the server response information of the HTTP request through a custom abnormal monitoring function" may specifically include:
[0120] Obtain the server response message corresponding to the request object through a custom exception monitoring function;
[0121] Parse the server response message to monitor abnormal events.
[0122] Wherein, in the case of calling the XMLHttpRequest function, the server response information is a message containing a character or string of a preset type.
[0123] The custom exception monitoring function can parse the characters or strings in the server response message to determine whether the HTTP request is normal. If the HTTP request is determined to be abnormal, the specific abnormal event can be further determined based on the server response message.
[0124] That is, the step of “parsing the server response message to monitor abnormal events” may specifically include:
[0125] Parse the server response message to obtain the status indication parameter in the server response message;
[0126] If the status indication parameter indicates that an abnormality occurs in the HTTP request, based on a preset mapping relationship between the status indication parameter and the abnormal event type, the abnormal event corresponding to the HTTP request is determined, and the abnormal event is monitored.
[0127] For example, Figure 3 As shown, it is possible to first determine whether the HTTP request is normal, and if it is determined that the HTTP request is abnormal, the specific abnormal event can be further determined according to the server response message. The abnormal event may include an error event (error) or a timeout event (timeout) and other events.
[0128] Optionally, when the target API function includes a Fetch function, the step of "monitoring abnormal events based on server response information of HTTP requests through a custom abnormal monitoring function" includes:
[0129] Through the custom exception monitoring function, the server response object corresponding to the received HTTP request is parsed to obtain the HTTP status code in the server response object;
[0130] Monitor abnormal events based on HTTP status codes.
[0131] When the Fetch function is called, the server response information is in the form of an object, namely, a server response object.
[0132] The custom exception monitoring function can parse the server response object and determine whether the HTTP request is normal. If the HTTP request is determined to be abnormal, the specific abnormal event can be further determined based on the HTTP status code in the server response object.
[0133] That is, the step of "parse the server response object corresponding to the received HTTP request through a custom exception monitoring function to obtain the HTTP status code in the server response object" may include:
[0134] Through the custom exception monitoring function, the server response object corresponding to the received HTTP request is parsed to obtain the status indication parameter in the server response object;
[0135] If the status indication parameter indicates that an exception occurs in the HTTP request, the HTTP status code in the server response object is obtained.
[0136] For example, Figure 3 As shown, you can first determine whether the HTTP request is normal. If the HTTP request is abnormal, you can further determine the specific abnormal event based on the HTTP status code in the server response object. Abnormal events may include abnormal events such as server rejection of request, server not understanding the syntax of the request, and interface cross-domain.
[0137] 205. If an abnormal event is monitored, obtain the HTTP request log corresponding to the abnormal event and report it.
[0138] It is understandable that if no abnormal event is monitored, the HTTP request log of the HTTP request may not be obtained to avoid occupying storage resources and transmission resources.
[0139] In some optional embodiments, a fixed storage location may be set in the client, and the HTTP request log corresponding to the abnormal event may be stored according to the corresponding function of the HTTP request in the client.
[0140] In some other optional embodiments, in order to improve the response speed of the client and enhance the stability of the client, the HTTP request log can be stored in a queue. Before the step of "determining the HTTP request program that responds to the HTTP request triggering event", the abnormal request capture method provided by the embodiment of the present invention can also include:
[0141] Create an exception request log queue, which is used to store logs corresponding to abnormal HTTP requests.
[0142] There may be only one or more exception request log queues. When there are multiple exception request log queues, different exception request log queues may correspond to different functions of the client, and developers may set them according to actual needs.
[0143] Accordingly, the step "obtaining the HTTP request log corresponding to the abnormal event and reporting it" includes:
[0144] Obtain the HTTP request log corresponding to the abnormal event, and store the HTTP request log in the abnormal request log queue;
[0145] Report the HTTP request logs in the abnormal request log queue.
[0146] Specifically, when the XMLHttpRequest function is called, a monitoring callback function can be written in the HTTP request program. When obtaining the HTTP request log corresponding to the abnormal event, the HTTP request log can be obtained through the monitoring callback function.
[0147] When the Fetch function is called, a then statement can be written in the HTTP request program to obtain the HTTP request log corresponding to the abnormal event.
[0148] It is understandable that in actual application, a special log reporting platform can be set up to collect HTTP request logs of abnormal HTTP requests, and the collected HTTP request logs can also be processed. Before the step of "reporting the HTTP request logs in the abnormal request log queue", the abnormal request capture method provided by the embodiment of the present invention can also include:
[0149] Determine the target reporting platform for HTTP request logs and obtain the log reporting API of the target reporting platform;
[0150] Based on the log reporting API, a log reporting function is generated, which includes a log reporting sub-function and a reporting exception capture sub-function.
[0151] Specifically, the target reporting platform is a log reporting platform for reporting HTTP request logs. Different clients or different log generation times may correspond to different log reporting platforms.
[0152] The log reporting function is a function encapsulated by calling the log reporting API provided by the target reporting platform. The log reporting sub-function can realize the reporting of HTTP requests to the target reporting platform. The reporting exception capture sub-function can be used to capture exceptions in the log reporting process.
[0153] Accordingly, the step of "reporting the HTTP request log in the abnormal request log queue" includes:
[0154] The abnormal request log in the abnormal request log queue is reported through the log reporting sub-function.
[0155] Furthermore, the abnormal request capture method provided by the embodiment of the present invention may also include:
[0156] Based on the reporting exception capture sub-function, record the number of exceptions reported when reporting through the log reporting sub-function;
[0157] If the number of exceptions is not less than the preset exception threshold, stop reporting the HTTP request log.
[0158] Specifically, the abnormal number threshold may be a value such as 5. For example, when the abnormality is reported more than five times, the current reporting process may be terminated. It is understandable that more conditions for terminating the report may be set in the embodiment of the present invention, for example, the abnormal number within 10 minutes may be not less than the preset abnormal number threshold, or the abnormal number of consecutive abnormal reports may be not less than the preset abnormal number threshold, and so on.
[0159] In some optional embodiments, in order to avoid the impact of the log reporting process on key events of the client, such as page refresh, etc., the HTTP request log can be reported when the client is idle. Before the step of "reporting the HTTP request log in the abnormal request log queue", the abnormal request capture method provided by the embodiment of the present invention may also include:
[0160] Determine the target reporting platform for HTTP request logs and obtain the log reporting API of the target reporting platform;
[0161] Based on the log reporting API, a log reporting function is generated. The log reporting function includes running an idle detection function and a log reporting sub-function.
[0162] Add the log reporting function to the client program.
[0163] Among them, running the idle detection function can be used to detect whether the client is currently in an idle state.
[0164] Correspondingly, the step of "reporting the HTTP request log in the abnormal request log queue" may specifically include:
[0165] Detect the working status of the client by running the idle detection function;
[0166] When the working state of the client is idle, the HTTP request log in the abnormal request log queue is reported through the log reporting sub-function.
[0167] Specifically, a window.requestIdleCallback() function may be added to the client, and a log reporting function may be inserted into the window.requestIdleCallback() function, so that the client may report HTTP requests that have not been reported in the abnormal request log queue when in an idle state.
[0168] As can be seen from the above, the embodiment of the present invention can determine the HTTP request program that responds to the HTTP request triggering event based on the HTTP request triggering event of the client, the HTTP request program is at least used to generate the HTTP request, determine the target API function that needs to be called when the HTTP request program generates the HTTP request, the target API function includes a custom exception monitoring function, the custom exception monitoring function is customized by the development side of the client, based on the HTTP request program calling the target API function to generate the HTTP request and send it to the server, and calling the custom exception monitoring function in the target API function, through the custom exception monitoring function, based on the server response information of the HTTP request, monitor the abnormal event, if the abnormal event is monitored, obtain the HTTP request log corresponding to the abnormal event and report it; because in the embodiment of the present invention, the target API function to be called when the HTTP request is generated is modified, and the custom exception monitoring function is directly added to the target API function that cannot be bypassed when the request is generated, therefore, no matter which API the developer uses, it is necessary to call the target API function and then call the custom exception monitoring function, so that the abnormal HTTP request in the Web application can be fully and timely captured, and the custom exception monitoring function is directly transformed into the target API function, without the need for the developer to write the relevant code about the abnormal capture by himself, which can reduce the development burden of the developer and reduce the development cost of the Web application.
[0169] The method described in the above embodiments is further described in detail below with examples.
[0170] In this embodiment, the Figure 1 system is described below.
[0171] like Figure 4 As shown, the specific process of the abnormal request capture method of this embodiment can be as follows:
[0172] 401. The terminal creates an abnormal request log queue in response to a user's startup operation on a client.
[0173] 402. Based on the HTTP request triggering event of the client, determine an HTTP request program that responds to the HTTP request triggering event, where the HTTP request program is at least used to generate an HTTP request.
[0174] In the embodiment of the present invention, the underlying technical solutions for implementing HTTP in Web applications are all implemented based on the XMLHttpRequest function or Fetch function of the Web API, and the development side of the client has modified the XMLHttpRequest function and the Fetch function in advance.
[0175] For the XMLHttpRequest function, the development side modifies the open() function used to initialize the request so that the modified open() function can obtain the interface address when initializing the request (open), and add the address to the XMLHttpRequest object through the statement this.ajaxUrl=url.
[0176] The development side also modifies the send() function used to send requests, so that the modified send() function can monitor abnormal events such as error events (error) and timeout events (timeout) when sending requests.
[0177] For the Fetch function, the development side modifies the fetch() function used to obtain resources so that the modified fetch() function monitors the Response.ok value when the interface responds. If the HTTP status code is not in the range of 200-299 (Response.ok=true), it is treated as an exception.
[0178] The development side also uses the modified fetch() function to capture cross-domain interface situations and treat it as an exception when the Response.type value is cors.
[0179] 403. Determine the target API function that the HTTP request program needs to call when generating the HTTP request. If the target API function is the XMLHttpRequest function, execute step 404. If the target API function is the Fetch function, execute step 405.
[0180] The target API function includes a custom exception monitoring function, and the custom exception monitoring function is customized by the development side of the client.
[0181] 404. Based on the request object corresponding to the HTTP request program, call the XMLHttpRequest function to generate an HTTP request, send the HTTP request to the server, and call the custom exception listening function in the XMLHttpRequest function.
[0182] Optionally, the XMLHttpRequest function may include a custom initialization function. Before the step of "based on the request object corresponding to the HTTP request program, calling the XMLHttpRequest function to generate an HTTP request", the abnormal request capture method provided by the embodiment of the present invention may further include:
[0183] Based on the HTTP request program, create a request object corresponding to the HTTP request program;
[0184] Call the custom initialization function to initialize the request object;
[0185] Through the custom initialization function, add the interface address in the custom initialization function to the request object.
[0186] It is understandable that during one operation of the client, an object may be created only once, and during subsequent operations of the client, if the same request needs to be sent again, it may be implemented directly based on the created object.
[0187] 405. Based on the HTTP request program, the Fetch function is called to generate an HTTP request, the HTTP request is sent to the server, and the custom exception listening function in the Fetch function is called.
[0188] Specifically, the developer can rewrite the fetch() function in the Fetch function and add a custom exception monitoring function that can monitor the server's Response to the function.
[0189] After the client sends an HTTP request, the custom exception listening function can monitor the server response information returned by the server.
[0190] 406. Monitor abnormal events based on the server response information of the HTTP request through a custom exception monitoring function.
[0191] Wherein, in the case of calling the XMLHttpRequest function, the server response information is a message containing a character or string of a preset type.
[0192] The custom exception monitoring function can parse the characters or strings in the server response message to determine whether the HTTP request is normal. If the HTTP request is determined to be abnormal, the specific abnormal event can be further determined based on the server response message.
[0193] When the Fetch function is called, the server response information is in the form of an object, namely, a server response object.
[0194] The custom exception monitoring function can parse the server response object and determine whether the HTTP request is normal. If the HTTP request is determined to be abnormal, the specific abnormal event can be further determined based on the HTTP status code in the server response object.
[0195] 407. Obtain the HTTP request log corresponding to the abnormal event, and store the HTTP request log in the abnormal request log queue.
[0196] In an embodiment of the present invention, the development side of the client encapsulates the log reporting interface call provided by the server into a public log reporting function; and captures the exception of the log reporting interface, sets a counter, and terminates the current reporting behavior if the exception is reported more than 5 times in a row.
[0197] 408. Report the HTTP request log in the abnormal request log queue.
[0198] The development side inserts the log reporting function in the window.requestIdleCallback() function, and then the client will report the HTTP request logs to be reported in the abnormal request log queue during the idle period. This can perform background and low-priority work on the main event loop without affecting the delay of key events.
[0199] As can be seen from the above, the embodiment of the present invention can determine the HTTP request program that responds to the HTTP request triggering event based on the HTTP request triggering event of the client, the HTTP request program is at least used to generate the HTTP request, determine the target API function that needs to be called when the HTTP request program generates the HTTP request, the target API function includes a custom exception monitoring function, the custom exception monitoring function is customized by the development side of the client, based on the HTTP request program calling the target API function to generate the HTTP request and send it to the server, and calling the custom exception monitoring function in the target API function, through the custom exception monitoring function, based on the server response information of the HTTP request, monitor the abnormal event, if the abnormal event is monitored, obtain the HTTP request log corresponding to the abnormal event and report it; because in the embodiment of the present invention, the target API function to be called when the HTTP request is generated is modified, and the custom exception monitoring function is directly added to the target API function that cannot be bypassed when the request is generated, therefore, no matter which API the developer uses, it is necessary to call the target API function and then call the custom exception monitoring function, so that the abnormal HTTP request in the Web application can be fully and timely captured, and the custom exception monitoring function is directly transformed into the target API function, without the need for the developer to write the relevant code about the abnormal capture by himself, which can reduce the development burden of the developer and reduce the development cost of the Web application.
[0200] In order to better implement the above method, accordingly, an embodiment of the present invention further provides an abnormal request capturing device.
[0201] refer to Figure 5 , the device comprises:
[0202] The program determination unit 501 may be used to determine an HTTP request program that responds to an HTTP request triggering event based on an HTTP request triggering event of a client, and the HTTP request program may at least be used to generate an HTTP request;
[0203] The function determination unit 502 may be used to determine the target API function that needs to be called when the HTTP request program generates an HTTP request. The target API function may include a custom exception monitoring function, which is customized by the development side of the client.
[0204] The function calling unit 503 may be used to call the target API function based on the HTTP request program to generate an HTTP request and send it to the server, and call a custom exception monitoring function in the target API function;
[0205] The event monitoring unit 504 can be used to monitor abnormal events based on the server response information of the HTTP request through a custom abnormal monitoring function;
[0206] The log reporting unit 505 may be used to obtain and report the HTTP request log corresponding to an abnormal event if an abnormal event is monitored.
[0207] In some optional embodiments, such as Figure 6 As shown, the abnormal request capture device provided by the embodiment of the present invention may further include a queue creation unit 506, which may be used to create an abnormal request log queue, and the abnormal request log queue may be used to store logs corresponding to abnormal HTTP requests;
[0208] The log reporting unit 505 can be used to obtain the HTTP request log corresponding to the abnormal event and store the HTTP request log in the abnormal request log queue;
[0209] Report the HTTP request logs in the abnormal request log queue.
[0210] In some optional embodiments, the target API function may include an XMLHttpRequest function, and the function calling unit 503 may be used to call the XMLHttpRequest function to generate an HTTP request based on a request object corresponding to the HTTP request program;
[0211] Send an HTTP request to the server and call the custom exception listening function in the XMLHttpRequest function;
[0212] The event monitoring unit 504 can be used to obtain the server response message corresponding to the request object through a custom exception monitoring function;
[0213] Parse the server response message to monitor abnormal events.
[0214] In some optional embodiments, the XMLHttpRequest function may include a custom initialization function, and the abnormal request capture device provided by the embodiment of the present invention may also include an object initialization unit, which can be used to create a request object corresponding to the HTTP request program based on the HTTP request program;
[0215] Call the custom initialization function to initialize the request object;
[0216] Through the custom initialization function, add the interface address in the custom initialization function to the request object;
[0217] The log reporting unit 505 can be used to obtain the interface address in the request object and write the HTTP request log corresponding to the abnormal event if an abnormal event is monitored;
[0218] Obtain HTTP request logs and report them.
[0219] In some optional embodiments, the target API function may include a Fetch function, and the function calling unit may be used to generate an HTTP request based on an HTTP request program calling the Fetch function;
[0220] Send an HTTP request to the server and call the custom exception listening function in the Fetch function;
[0221] The event monitoring unit 504 can be used to parse the server response object corresponding to the received HTTP request through a custom exception monitoring function to obtain the HTTP status code in the server response object;
[0222] Monitor abnormal events based on HTTP status codes.
[0223] In some optional embodiments, the abnormal request capture device provided by the embodiment of the present invention may further include a function generation unit 507, which may be used to determine a target reporting platform for HTTP request logs and obtain a log reporting API of the target reporting platform;
[0224] Based on the log reporting API, a log reporting function is generated. The log reporting function may include a log reporting sub-function and a reporting exception capture sub-function;
[0225] The log reporting unit 505 can be used to report the abnormal request log in the abnormal request log queue through the log reporting sub-function;
[0226] The abnormal request capture device provided by the embodiment of the present invention may further include a reporting stop unit 508, which may be used to record the number of abnormalities of reporting abnormalities when reporting through the log reporting sub-function based on the reporting abnormality capture sub-function;
[0227] If the number of exceptions is not less than the preset exception threshold, stop reporting the HTTP request log.
[0228] In some optional embodiments, the abnormal request capture device provided by the embodiment of the present invention may further include a function generation unit 507, which may be used to determine a target reporting platform for HTTP request logs and obtain a log reporting API of the target reporting platform;
[0229] Based on the log reporting API, a log reporting function is generated. The log reporting function may include an idle detection function and a log reporting sub-function.
[0230] Add the log reporting function to the client program;
[0231] The log reporting unit 505 can be used to detect the working status of the client by running an idle detection function;
[0232] When the working state of the client is idle, the HTTP request log in the abnormal request log queue is reported through the log reporting sub-function.
[0233] As can be seen from the above, through the abnormal request capture device, based on the HTTP request trigger event of the client, the HTTP request program that responds to the HTTP request trigger event can be determined, the HTTP request program is at least used to generate the HTTP request, and the target API function that needs to be called when the HTTP request program generates the HTTP request is determined. The target API function includes a custom abnormal monitoring function, which is customized by the development side of the client, based on the HTTP request program calling the target API function to generate an HTTP request and send it to the server, and calling the custom abnormal monitoring function in the target API function, through the custom abnormal monitoring function, based on the server response information of the HTTP request, the abnormal event is monitored, if the abnormal event is monitored, the HTTP request log corresponding to the abnormal event is obtained and reported; because in the embodiment of the present invention, the target API function to be called when the HTTP request is generated is modified, and the custom abnormal monitoring function is directly added to the target API function that cannot be bypassed when the request is generated, therefore, no matter which API the developer uses, it is necessary to call the target API function and then call the custom abnormal monitoring function, so that the abnormal HTTP request in the Web application can be fully and timely captured, and the custom abnormal monitoring function is directly transformed into the target API function, without the need for the developer to write the relevant code about the abnormal capture by himself, which can reduce the development burden of the developer and reduce the development cost of the Web application.
[0234] In addition, correspondingly, the embodiment of the present application also provides a computer device, which may be a terminal. Figure 7 As shown, Figure 7 A schematic diagram of the structure of a computer device provided in an embodiment of the present application. The computer device 700 includes a processor 701 having one or more processing cores, a memory 702 having one or more computer-readable storage media, and a computer program stored in the memory 702 and executable on the processor. The processor 701 is electrically connected to the memory 702. Those skilled in the art will appreciate that the computer device structure shown in the figure does not constitute a limitation on the computer device, and may include more or fewer components than shown, or combine certain components, or arrange components differently.
[0235] The processor 701 is the control center of the computer device 700. It uses various interfaces and lines to connect the various parts of the entire computer device 700, executes various functions of the computer device 700 and processes data by running or loading software programs and / or modules stored in the memory 702, and calling data stored in the memory 702, thereby monitoring the computer device 700 as a whole.
[0236] In the embodiment of the present application, the processor 701 in the computer device 700 will load instructions corresponding to the processes of one or more application programs into the memory 702 according to the following steps, and the processor 701 will run the application programs stored in the memory 702 to implement various functions:
[0237] Based on the HTTP request triggering event of the client, determining an HTTP request program that responds to the HTTP request triggering event, the HTTP request program being used to generate at least an HTTP request;
[0238] Determine the target API function that needs to be called when the HTTP request program generates an HTTP request. The target API function includes a custom exception monitoring function, which is customized by the development side of the client.
[0239] Based on the HTTP request program, the target API function is called to generate an HTTP request and sent to the server, and a custom exception listening function in the target API function is called;
[0240] Through the custom exception monitoring function, the server response information based on the HTTP request is used to monitor the abnormal events;
[0241] If an abnormal event is detected, obtain the HTTP request log corresponding to the abnormal event and report it.
[0242] In some embodiments, before determining the HTTP request program that responds to the HTTP request triggering event, the abnormal request capture method provided by the embodiment of the present invention further includes:
[0243] Create an exception request log queue, which is used to store logs corresponding to abnormal HTTP requests;
[0244] Obtain and report the HTTP request log corresponding to the abnormal event, including:
[0245] Obtain the HTTP request log corresponding to the abnormal event, and store the HTTP request log in the abnormal request log queue;
[0246] Report the HTTP request logs in the abnormal request log queue.
[0247] In some embodiments, the target API function includes an XMLHttpRequest function, and the HTTP request program calls the target API function to generate an HTTP request and sends it to the server, and calls a custom exception listening function in the target API function, including:
[0248] Based on the request object corresponding to the HTTP request program, call the XMLHttpRequest function to generate an HTTP request;
[0249] Send an HTTP request to the server and call the custom exception listening function in the XMLHttpRequest function;
[0250] Through the custom exception monitoring function, the server response information based on the HTTP request is used to monitor the abnormal events, including:
[0251] Obtain the server response message corresponding to the request object through a custom exception monitoring function;
[0252] Parse the server response message to monitor abnormal events.
[0253] In some embodiments, the XMLHttpRequest function includes a custom initialization function, and before calling the XMLHttpRequest function to generate an HTTP request based on a request object corresponding to the HTTP request program, the method further includes:
[0254] Based on the HTTP request program, create a request object corresponding to the HTTP request program;
[0255] Call the custom initialization function to initialize the request object;
[0256] Through the custom initialization function, add the interface address in the custom initialization function to the request object;
[0257] If an abnormal event is detected, obtain the HTTP request log corresponding to the abnormal event and report it, including:
[0258] If an abnormal event is detected, obtain the interface address in the request object and write it into the HTTP request log corresponding to the abnormal event;
[0259] Obtain HTTP request logs and report them.
[0260] In some embodiments, the target API function includes a Fetch function, and based on the HTTP request program, the target API function is called to generate an HTTP request and sent to the server, and a custom exception listening function in the target API function is called, including:
[0261] Based on the HTTP request program, call the Fetch function to generate an HTTP request;
[0262] Send an HTTP request to the server and call the custom exception listening function in the Fetch function;
[0263] Through the custom exception monitoring function, the server response information based on the HTTP request is used to monitor the abnormal events, including:
[0264] Through the custom exception monitoring function, the server response object corresponding to the received HTTP request is parsed to obtain the HTTP status code in the server response object;
[0265] Monitor abnormal events based on HTTP status codes.
[0266] In some embodiments, before reporting the HTTP request log in the abnormal request log queue, the abnormal request capture method provided by the embodiment of the present invention further includes:
[0267] Determine the target reporting platform for HTTP request logs and obtain the log reporting API of the target reporting platform;
[0268] Based on the log reporting API, a log reporting function is generated, which includes a log reporting sub-function and a reporting exception capture sub-function;
[0269] Report HTTP request logs in the abnormal request log queue, including:
[0270] The abnormal request log in the abnormal request log queue is reported through the log reporting sub-function;
[0271] The abnormal request capture method provided by the embodiment of the present invention also includes:
[0272] Based on the reporting exception capture sub-function, record the number of exceptions reported when reporting through the log reporting sub-function;
[0273] If the number of exceptions is not less than the preset exception threshold, stop reporting the HTTP request log.
[0274] In some embodiments, before reporting the HTTP request log in the abnormal request log queue, the abnormal request capture method provided by the embodiment of the present invention further includes:
[0275] Determine the target reporting platform for HTTP request logs and obtain the log reporting API of the target reporting platform;
[0276] Based on the log reporting API, a log reporting function is generated. The log reporting function includes running an idle detection function and a log reporting sub-function.
[0277] Add the log reporting function to the client program;
[0278] Report HTTP request logs in the abnormal request log queue, including:
[0279] Detect the working status of the client by running the idle detection function;
[0280] When the working state of the client is idle, the HTTP request log in the abnormal request log queue is reported through the log reporting sub-function.
[0281] This solution can determine an HTTP request program that responds to an HTTP request triggering event based on an HTTP request triggering event of a client, the HTTP request program is at least used to generate an HTTP request, and a target API function that needs to be called when the HTTP request program generates an HTTP request is determined, the target API function includes a custom exception monitoring function, the custom exception monitoring function is customized by the development side of the client, and based on the HTTP request program, the target API function is called to generate an HTTP request and send it to a server, the custom exception monitoring function in the target API function is called, and through the custom exception monitoring function, the server response information of the HTTP request is monitored based on the abnormal event, and if an abnormal event is monitored, the HTTP request log corresponding to the abnormal event is obtained and reported; the abnormal HTTP requests in the Web application can be fully and timely captured, the development burden of developers is reduced, and the development cost of the Web application is reduced.
[0282] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.
[0283] Optional, such as Figure 7 As shown, the computer device 700 further includes: a touch screen 703, a radio frequency circuit 704, an audio circuit 705, an input unit 706, and a power supply 707. The processor 701 is electrically connected to the touch screen 703, the radio frequency circuit 704, the audio circuit 705, the input unit 706, and the power supply 707, respectively. Those skilled in the art will appreciate that Figure 7 The computer device structure shown in the figure does not constitute a limitation on the computer device, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.
[0284] The touch display screen 703 can be used to display a graphical user interface and receive operation instructions generated by the user acting on the graphical user interface. The touch display screen 703 may include a display panel and a touch panel. Among them, the display panel may be used to display information input by the user or information provided to the user and various graphical user interfaces of the computer device, and these graphical user interfaces may be composed of graphics, text, icons, videos and any combination thereof. Optionally, the display panel may be configured in the form of a liquid crystal display (LCD, Liquid Crystal Display), an organic light emitting diode (OLED, Organic Light-Emitting Diode) and the like. The touch panel may be used to collect the user's touch operation on or near it (such as the user using any suitable object or attachment such as a finger, a stylus, etc. on the touch panel or near the touch panel), and generate corresponding operation instructions, and the operation instructions execute corresponding programs. Optionally, the touch panel may include two parts, a touch detection device and a touch controller. Among them, the touch detection device detects the user's touch orientation, detects the signal brought by the touch operation, and transmits the signal to the touch controller; the touch controller receives the touch information from the touch detection device, converts it into the touch point coordinates, and then sends it to the processor 701, and can receive the command sent by the processor 701 and execute it. The touch panel can cover the display panel. When the touch panel detects a touch operation on or near it, it is transmitted to the processor 701 to determine the type of touch event, and then the processor 701 provides a corresponding visual output on the display panel according to the type of touch event. In an embodiment of the present application, the touch panel and the display panel can be integrated into the touch display screen 703 to realize the input and output functions. However, in some embodiments, the touch panel and the touch panel can be used as two independent components to realize the input and output functions. That is, the touch display screen 703 can also be used as a part of the input unit 706 to realize the input function.
[0285] The RF circuit 704 may be used to send and receive RF signals, so as to establish wireless communication with a network device or other computer devices through wireless communication, and to send and receive signals between the network device or other computer devices.
[0286] The audio circuit 705 can be used to provide an audio interface between the user and the computer device through a speaker and a microphone. The audio circuit 705 can transmit the electrical signal converted from the received audio data to the speaker, which is converted into a sound signal for output; on the other hand, the microphone converts the collected sound signal into an electrical signal, which is received by the audio circuit 705 and converted into audio data, and then the audio data is output to the processor 701 for processing, and then sent to another computer device through the radio frequency circuit 704, or the audio data is output to the memory 702 for further processing. The audio circuit 705 may also include an earplug jack to provide communication between an external headset and the computer device.
[0287] The input unit 706 may be used to receive input numbers, character information or user feature information (such as fingerprint, iris, facial information, etc.), and generate keyboard, mouse, joystick, optical or trackball signal input related to user settings and function control.
[0288] The power supply 707 is used to supply power to various components of the computer device 700. Optionally, the power supply 707 can be logically connected to the processor 701 through a power management system, so that the power management system can manage charging, discharging, and power consumption. The power supply 707 can also include one or more DC or AC power supplies, recharging systems, power failure detection circuits, power converters or inverters, power status indicators, and other arbitrary components.
[0289] although Figure 7 Not shown, the computer device 700 may also include a camera, a sensor, a wireless fidelity module, a Bluetooth module, etc., which will not be described in detail here.
[0290] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0291] As can be seen from the above, the computer device provided in this embodiment determines an HTTP request program that responds to an HTTP request triggering event based on an HTTP request triggering event of a client, the HTTP request program is at least used to generate an HTTP request, and a target API function that needs to be called when the HTTP request program generates an HTTP request is determined, the target API function includes a custom exception monitoring function, the custom exception monitoring function is customized by the development side of the client, and based on the HTTP request program, the target API function is called to generate an HTTP request and send it to a server, the custom exception monitoring function in the target API function is called, and through the custom exception monitoring function, the server response information of the HTTP request is monitored based on the abnormal event, and if an abnormal event is monitored, the HTTP request log corresponding to the abnormal event is obtained and reported; the abnormal HTTP requests in the Web application can be captured comprehensively and timely, the development burden of developers is reduced, and the development cost of the Web application is reduced.
[0292] A person of ordinary skill in the art will appreciate that all or part of the steps in the various methods of the above embodiments may be completed by instructions, or by controlling related hardware through instructions. The instructions may be stored in a computer-readable storage medium and loaded and executed by a processor.
[0293] To this end, an embodiment of the present application provides a computer-readable storage medium, in which multiple computer programs are stored, and the computer program can be loaded by a processor to execute the steps in any of the abnormal request capture methods provided in the embodiments of the present application. For example, the computer program can execute the following steps:
[0294] Based on the HTTP request triggering event of the client, determining an HTTP request program that responds to the HTTP request triggering event, the HTTP request program being used to generate at least an HTTP request;
[0295] Determine the target API function that needs to be called when the HTTP request program generates an HTTP request. The target API function includes a custom exception monitoring function, which is customized by the development side of the client.
[0296] Based on the HTTP request program, the target API function is called to generate an HTTP request and sent to the server, and a custom exception listening function in the target API function is called;
[0297] Through the custom exception monitoring function, the server response information based on the HTTP request is used to monitor the abnormal events;
[0298] If an abnormal event is detected, obtain the HTTP request log corresponding to the abnormal event and report it.
[0299] In some embodiments, before determining the HTTP request program that responds to the HTTP request triggering event, the abnormal request capture method provided by the embodiment of the present invention further includes:
[0300] Create an exception request log queue, which is used to store logs corresponding to abnormal HTTP requests;
[0301] Obtain and report the HTTP request log corresponding to the abnormal event, including:
[0302] Obtain the HTTP request log corresponding to the abnormal event, and store the HTTP request log in the abnormal request log queue;
[0303] Report the HTTP request logs in the abnormal request log queue.
[0304] In some embodiments, the target API function includes an XMLHttpRequest function, and the HTTP request program calls the target API function to generate an HTTP request and sends it to the server, and calls a custom exception listening function in the target API function, including:
[0305] Based on the request object corresponding to the HTTP request program, call the XMLHttpRequest function to generate an HTTP request;
[0306] Send an HTTP request to the server and call the custom exception listening function in the XMLHttpRequest function;
[0307] Through the custom exception monitoring function, the server response information based on the HTTP request is used to monitor the abnormal events, including:
[0308] Obtain the server response message corresponding to the request object through a custom exception monitoring function;
[0309] Parse the server response message to monitor abnormal events.
[0310] In some embodiments, the XMLHttpRequest function includes a custom initialization function, and before calling the XMLHttpRequest function to generate an HTTP request based on a request object corresponding to the HTTP request program, the method further includes:
[0311] Based on the HTTP request program, create a request object corresponding to the HTTP request program;
[0312] Call the custom initialization function to initialize the request object;
[0313] Through the custom initialization function, add the interface address in the custom initialization function to the request object;
[0314] If an abnormal event is detected, obtain the HTTP request log corresponding to the abnormal event and report it, including:
[0315] If an abnormal event is detected, obtain the interface address in the request object and write it into the HTTP request log corresponding to the abnormal event;
[0316] Obtain HTTP request logs and report them.
[0317] In some embodiments, the target API function includes a Fetch function, and based on the HTTP request program, the target API function is called to generate an HTTP request and sent to the server, and a custom exception listening function in the target API function is called, including:
[0318] Based on the HTTP request program, call the Fetch function to generate an HTTP request;
[0319] Send an HTTP request to the server and call the custom exception listening function in the Fetch function;
[0320] Through the custom exception monitoring function, the server response information based on the HTTP request is used to monitor the abnormal events, including:
[0321] Through the custom exception monitoring function, the server response object corresponding to the received HTTP request is parsed to obtain the HTTP status code in the server response object;
[0322] Monitor abnormal events based on HTTP status codes.
[0323] In some embodiments, before reporting the HTTP request log in the abnormal request log queue, the abnormal request capture method provided by the embodiment of the present invention further includes:
[0324] Determine the target reporting platform for HTTP request logs and obtain the log reporting API of the target reporting platform;
[0325] Based on the log reporting API, a log reporting function is generated, which includes a log reporting sub-function and a reporting exception capture sub-function;
[0326] Report HTTP request logs in the abnormal request log queue, including:
[0327] The abnormal request log in the abnormal request log queue is reported through the log reporting sub-function;
[0328] The abnormal request capture method provided by the embodiment of the present invention also includes:
[0329] Based on the reporting exception capture sub-function, record the number of exceptions reported when reporting through the log reporting sub-function;
[0330] If the number of exceptions is not less than the preset exception threshold, stop reporting the HTTP request log.
[0331] In some embodiments, before reporting the HTTP request log in the abnormal request log queue, the abnormal request capture method provided by the embodiment of the present invention further includes:
[0332] Determine the target reporting platform for HTTP request logs and obtain the log reporting API of the target reporting platform;
[0333] Based on the log reporting API, a log reporting function is generated. The log reporting function includes running an idle detection function and a log reporting sub-function.
[0334] Add the log reporting function to the client program;
[0335] Report HTTP request logs in the abnormal request log queue, including:
[0336] Detect the working status of the client by running the idle detection function;
[0337] When the working state of the client is idle, the HTTP request log in the abnormal request log queue is reported through the log reporting sub-function.
[0338] This solution can determine an HTTP request program that responds to an HTTP request triggering event based on an HTTP request triggering event of a client, the HTTP request program is at least used to generate an HTTP request, and a target API function that needs to be called when the HTTP request program generates an HTTP request is determined, the target API function includes a custom exception monitoring function, the custom exception monitoring function is customized by the development side of the client, and based on the HTTP request program, the target API function is called to generate an HTTP request and send it to a server, the custom exception monitoring function in the target API function is called, and through the custom exception monitoring function, the server response information of the HTTP request is monitored based on the abnormal event, and if an abnormal event is monitored, the HTTP request log corresponding to the abnormal event is obtained and reported; the abnormal HTTP requests in the Web application can be fully and timely captured, the development burden of developers is reduced, and the development cost of the Web application is reduced.
[0339] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.
[0340] The storage medium may include: a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0341] Since the computer program stored in the storage medium can execute the steps in any one of the abnormal request capture methods provided in the embodiments of the present application, the beneficial effects that can be achieved by any one of the abnormal request capture methods provided in the embodiments of the present application can be achieved. Please refer to the previous embodiments for details and will not be repeated here.
[0342] The above is a detailed introduction to an abnormal request capture method, device, storage medium and computer equipment provided in an embodiment of the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for technical personnel in this field, according to the idea of the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A method for capturing abnormal requests, characterized in that: Applied to a client, the method comprises: Based on the HTTP request triggering event of the client, determining an HTTP request program that responds to the HTTP request triggering event, wherein the HTTP request program is at least used to generate an HTTP request; Determine, from the XMLHttpRequest function and the Fetch function, a target API function that needs to be called when the HTTP request program generates an HTTP request, wherein the target API function also includes a custom exception monitoring function, and the custom exception monitoring function is customized by the development side of the client; Based on the HTTP request program, the target API function is called to generate an HTTP request and sent to the server, and the custom exception monitoring function in the target API function is called; Monitoring abnormal events based on the server response information of the HTTP request through the custom abnormal monitoring function; If an abnormal event is detected, obtain the HTTP request log corresponding to the abnormal event and report it.
2. The abnormal request capture method according to claim 1, characterized in that: Before determining the HTTP request program that responds to the HTTP request triggering event, the method further includes: Create an abnormal request log queue, the abnormal request log queue is used to store logs corresponding to abnormal HTTP requests; The obtaining and reporting of the HTTP request log corresponding to the abnormal event includes: Obtaining the HTTP request log corresponding to the abnormal event, and storing the HTTP request log in the abnormal request log queue; The HTTP request log in the abnormal request log queue is reported.
3. The abnormal request capture method according to any one of claims 1-2, characterized in that: The target API function includes an XMLHttpRequest function, the step of calling the target API function based on the HTTP request program to generate an HTTP request and sending the HTTP request to the server, and calling the custom exception monitoring function in the target API function includes: Based on the request object corresponding to the HTTP request program, calling the XMLHttpRequest function to generate an HTTP request; Send the HTTP request to the server, and call the custom exception monitoring function in the XMLHttpRequest function; The monitoring of abnormal events based on the server response information of the HTTP request through the custom abnormal monitoring function includes: Obtaining the server response message corresponding to the request object through the custom exception monitoring function; The server response message is parsed to monitor abnormal events.
4. The abnormal request capture method according to claim 3, characterized in that: The XMLHttpRequest function includes a custom initialization function. Before calling the XMLHttpRequest function to generate an HTTP request based on the request object corresponding to the HTTP request program, the method further includes: Based on the HTTP request program, create a request object corresponding to the HTTP request program; Calling the custom initialization function to initialize the request object; By means of the custom initialization function, the interface address in the custom initialization function is added to the request object; If an abnormal event is monitored, obtaining the HTTP request log corresponding to the abnormal event and reporting it includes: If an abnormal event is monitored, obtain the interface address in the request object and write it into the HTTP request log corresponding to the abnormal event; Obtain the HTTP request log and report it.
5. The abnormal request capture method according to any one of claims 1-2, characterized in that: The target API function includes a Fetch function, the step of calling the target API function based on the HTTP request program to generate an HTTP request and sending the request to the server, and calling the custom exception monitoring function in the target API function includes: Calling the Fetch function based on the HTTP request program to generate an HTTP request; Send an HTTP request to the server and call the custom exception listening function in the Fetch function; The monitoring of abnormal events based on the server response information of the HTTP request through the custom abnormal monitoring function includes: Parsing the server response object corresponding to the received HTTP request through the custom exception monitoring function to obtain the HTTP status code in the server response object; Based on the HTTP status code, abnormal events are monitored.
6. The abnormal request capture method according to claim 2, characterized in that: Before reporting the HTTP request log in the abnormal request log queue, the method further includes: Determine a target reporting platform for the HTTP request log, and obtain a log reporting API of the target reporting platform; Based on the log reporting API, a log reporting function is generated, wherein the log reporting function includes a log reporting sub-function and a reporting exception capture sub-function; The reporting of the HTTP request log in the abnormal request log queue includes: The abnormal request log in the abnormal request log queue is reported through the log reporting sub-function; The method further comprises: Based on the reporting exception capture sub-function, record the number of exceptions reported when reporting through the log reporting sub-function; If the number of exceptions is not less than a preset threshold number of exceptions, stop reporting the HTTP request log.
7. The abnormal request capture method according to claim 2, characterized in that: Before reporting the HTTP request log in the abnormal request log queue, the method further includes: Determine a target reporting platform for the HTTP request log, and obtain a log reporting API of the target reporting platform; Based on the log reporting API, a log reporting function is generated, wherein the log reporting function includes a running idle detection function and a log reporting sub-function; Add the log reporting function to the client program; The reporting of the HTTP request log in the abnormal request log queue includes: Detecting the working status of the client by running the idle detection function; When the working state of the client is an idle state, the HTTP request log in the abnormal request log queue is reported through the log reporting sub-function.
8. An abnormal request capture device, characterized in that: include: A program determining unit, configured to determine, based on an HTTP request triggering event of a client, an HTTP request program that responds to the HTTP request triggering event, wherein the HTTP request program is at least configured to generate an HTTP request; A function determination unit, used to determine, from the XMLHttpRequest function and the Fetch function, a target API function to be called when the HTTP request program generates an HTTP request, wherein the target API function also includes a custom exception monitoring function, and the custom exception monitoring function is customized by the development side of the client; A function calling unit, configured to call the target API function based on the HTTP request program to generate an HTTP request and send the request to the server, and to call the custom exception monitoring function in the target API function; An event monitoring unit, used to monitor abnormal events based on the server response information of the HTTP request through the custom abnormal monitoring function; The log reporting unit is used to obtain and report the HTTP request log corresponding to the abnormal event if an abnormal event is monitored.
9. An electronic device, characterized in that: It comprises a memory and a processor; the memory stores an application program, and the processor is used to run the application program in the memory to execute the steps in the abnormal request capture method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a plurality of instructions, and the instructions are suitable for being loaded by a processor to execute the steps in the abnormal request capturing method according to any one of claims 1 to 7.
11. A computer program product comprising a computer program or instructions, characterized in that When the computer program or instruction is executed by a processor, the steps of the abnormal request capturing method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Method and apparatus for monitoring asynchronous request of dynamic webpage
CN106294408A
Fast application exception handling method and device, electronic equipment and storage medium
CN112069034A