Summary of the invention
Embodiment of the disclosure proposes the method and apparatus for sending network request.
In a first aspect, embodiment of the disclosure provides a kind of method for sending network request, this method comprises: really
Fixed whether detect is used to indicate the user's request for sending target network request, wherein target network request belongs to preset net
Network request collection;In response to confirmly detecting user's request, class belonging to the object of target network request to be sent is determined, wherein
Identified class follows network request agreement or network request interface, wherein network request agreement or network request interface are used for
The method for being packaged for sending the network request that network request is concentrated;Call its corresponding for sending mesh by identified class
The method of network request is marked to send target network request.
In some embodiments, network request collection includes being used to indicate the network request interacted with server-side.
In some embodiments, it then follows network request agreement or the class of network request interface include first object class and second
Target class, wherein first object class realizes that is encapsulated in network request agreement or network request interface is used to send network request
Method be for sending the network request that interacts with server-side of instruction, the second target class realization network request agreement or network are asked
Seeking the method for sending network request encapsulated in interface is the network request interacted for sending instruction with target database.
In some embodiments, target database includes local data base.
Second aspect, embodiment of the disclosure provide a kind of for sending the device of network request, which includes: use
Determination unit is requested at family, is configured to determine and whether is detected that being used to indicate the user for sending target network request requests, wherein
Target network request belongs to preset network request collection;Class determination unit is configured in response to confirmly detect user's request,
Determine class belonging to the object of target network request to be sent, wherein identified class follows network request agreement or network is asked
Seek interface, wherein network request agreement or network request interface are used to be packaged for send the network request that network request is concentrated
Method;Transmission unit, the method for being configured to call its corresponding by identified class for sending target network request
To send target network request.
In some embodiments, network request collection includes being used to indicate the network request interacted with server-side.
In some embodiments, it then follows network request agreement or the class of network request interface include first object class and second
Target class, wherein first object class realizes that is encapsulated in network request agreement or network request interface is used to send network request
Method be for sending the network request that interacts with server-side of instruction, the second target class realization network request agreement or network are asked
Seeking the method for sending network request encapsulated in interface is the network request interacted for sending instruction with target database.
In some embodiments, target database includes local data base.
The third aspect, embodiment of the disclosure provide a kind of terminal, which includes: one or more processors;It deposits
Storage device, for storing one or more programs;When one or more programs are executed by one or more processors, so that one
Or multiple processors realize the method as described in implementation any in first aspect.
Fourth aspect, embodiment of the disclosure provide a kind of computer-readable medium, are stored thereon with computer program,
The method as described in implementation any in first aspect is realized when the computer program is executed by processor.
The method and apparatus for sending network request that embodiment of the disclosure provides, by by different types of network
General some methods for sending network request of request are packaged into agreement or interface, then by needing to send network request
Different scenes corresponding to class all follow packaged agreement or interface so that needing to send the different fields of network request
Class corresponding to scape all necessarily realizes the method that network request is sent defined in packaged agreement or interface.Therefore, exist
Specifically need to send under the scene of network request, can the class as belonging to the object of network request to be sent call directly transmission
The method of network request, so that it may realize the transmission of network request.
Corresponding network request is all preset respectively with the scene in the prior art for every kind of transmission network request
Class, and the method for defining by corresponding network request class the transmission network request under different scenes is compared, due in the prior art
This mode under the scene for specifically needing to send network request, belonging to the object that needs first to judge network request to be sent
Class, and then class belonging to the object of network request to be sent could be instantiated, the corresponding network request class of a step of going forward side by side
In transmission network request method to send network request.
And method provided by embodiment of the disclosure is by allowing under different scenes the class for needing to send network request all to be abided by
The agreement or interface for encapsulating general some methods for being used to send network request of different types of network request are followed, thus
The class for needing to send network request under different scenes is allowed to call directly the corresponding method for sending network request to send
Network request.Compared to the prior art, it does not need all to preset respectively for the scene of every kind of transmission network request corresponding
Network request class first judges network request to be sent to also not need under the scene for specifically needing to send network request
Object belonging to class.The workload of technical staff is not only alleviated, but also helps to promote the speed for sending network request.
In addition, above-mentioned mode in the prior art is more and more with the scene for needing to send network request, corresponding hair
The processing logic of SCN Space Cable Network request can also become increasingly complex naturally.For example, judging class belonging to the object of network request to be sent
This logic judgment process will with the increase for the scene for needing to send network request even more complex.Accordingly, this is patrolled
It is naturally also longer to collect deterministic process the time it takes.And handle logic it is excessively complicated when, developer's also error-prone,
The problems such as so as to cause application crashes.It is avoided by method described in embodiment of the disclosure due to excessive logic judgment
And it is easy to appear the situation of mistake, it ensure that the stability of network request.
Specific embodiment
The disclosure is described in further detail with reference to the accompanying drawings and examples.It is understood that this place is retouched
The specific embodiment stated is used only for explaining related invention, rather than the restriction to the invention.It also should be noted that in order to
Convenient for description, part relevant to related invention is illustrated only in attached drawing.
It should be noted that in the absence of conflict, the feature in embodiment and embodiment in the disclosure can phase
Mutually combination.The disclosure is described in detail below with reference to the accompanying drawings and in conjunction with the embodiments.
Fig. 1 is shown can the method for sending network request using the disclosure or the dress for sending network request
The exemplary architecture 100 for the embodiment set.
As shown in Figure 1, system architecture 100 may include terminal device 101,102,103, network 104 and server 105.
Network 104 between terminal device 101,102,103 and server 105 to provide the medium of communication link.Network 104 can be with
Including various connection types, such as wired, wireless communication link or fiber optic cables etc..
Terminal device 101,102,103 is interacted by network 104 with server 105, to receive or send message etc..Terminal
Various client applications can be installed in equipment 101,102,103.For example, the application of browser class, searching class application, Instant Messenger
Believe class application, the application of content share class etc..
Terminal device 101,102,103 can be hardware, be also possible to software.When terminal device 101,102,103 is hard
When part, it can be various electronic equipments, including but not limited to smart phone, tablet computer, E-book reader, on knee portable
Computer and desktop computer etc..When terminal device 101,102,103 is software, above-mentioned cited electricity may be mounted at
In sub- equipment.Multiple softwares or software module may be implemented into (such as providing multiple softwares of Distributed Services or soft in it
Part module), single software or software module also may be implemented into.It is not specifically limited herein.
Server 105 can be to provide the server of various services, for example, be installed on terminal device 101,102,103
Application provide support back-end server.Server 105 can receive various nets transmitted by terminal device 101,102,103
Network request, and according to the received network request of institute, corresponding response message is returned to terminal device.
It should be noted that is installed on above-mentioned terminal device 101,102,103 exists using transmitted network request
Under some cases, response processing directly can also be carried out from the local of terminal device 101,102,103.At this point it is possible to be not present
Server 105 and network 104.
It should be noted that the method provided by embodiment of the disclosure for sending network request is generally set by terminal
Standby 101,102,103 execute, and correspondingly, the device for sending network request is generally positioned at terminal device 101,102,103
In.
It should be noted that server 105 can be hardware, it is also possible to software.It, can when server 105 is hardware
To be implemented as the distributed server cluster that multiple servers form, individual server also may be implemented into.When server 105 is
When software, multiple softwares or software module may be implemented into (such as providing multiple softwares of Distributed Services or software mould
Block), single software or software module also may be implemented into.It is not specifically limited herein.
It should be understood that the number of terminal device, network and server in Fig. 1 is only schematical.According to realization need
It wants, can have any number of terminal device, network and server.
With continued reference to Fig. 2, it illustrates according to one embodiment of the method for sending network request of the disclosure
Process 200.This be used for send network request method the following steps are included:
Step 201, it is determined whether detect and be used to indicate the user's request for sending target network request.
In the present embodiment, for send network request executing subject (terminal device as shown in Figure 1 101,102,
103) it can detecte and be used to indicate the user's request for sending network request.Wherein, under different application scenarios, user's request can
To trigger by various modes.
For example, user's request can be triggered by user's operation.As an example, user is utilizing above-mentioned executing subject
When browsing pushed information, it can be triggered by refresh operation (such as sliding page clicks refresh button) to server (such as Fig. 1
Shown in server 105) send the network request for obtaining new pushed information.
For example, user's request can also be according to preset some condition automatic triggers.As an example, in user to current exhibition
The page shown does not have any operation more than after certain time, can trigger the net for sending to server and obtaining new displaying information
Network request.
Wherein, network request can be various network requests.Such as the network request for obtaining data, for uploading number
According to network request etc..The indicated network request of user's request is target network request.
Wherein, target network request may belong to preset network request collection.Network request collection can be pre- by technical staff
First according to actual application demand flexible setting.Network request collection may include that the various scenes for needing to send network request are corresponding
Network request.
Step 202, in response to confirmly detecting user's request, belonging to the object for determining target network request to be sent
Class, wherein identified class follows network request agreement or network request interface.
In the present embodiment, it needs to send target network request, is necessarily required to specifically send the object of network request.Generally
Ground can determine the object of target network request to be sent according to the specific request content that target network is requested, and then can root
According to class belonging to the identified object acquisition object.
For example, target network request is used for the new displaying information of request current page, then target network to be sent
The main body of network request should be object (or example) example of class corresponding to current page.In another example target network is requested
The new page for requesting to open, then the main body of target network to be sent request should be that requested new page institute is right
The object for the class answered.
Wherein, the class of target network request to be sent can follow network request agreement or network request interface.Wherein, net
Network request protocol or network request interface can be used for being packaged for the method for sending the network request that network request is concentrated.
Network request agreement or network request interface can be preset to be packaged for sending what network request was concentrated
The method of various network requests.Specifically, it can be asked according to the network that network request corresponding under different scenes is concentrated
It asks, extracts the certain methods of some general (or public) of these network requests, and the reality by way of agreement or interface
It is existing.
Later, so that it may allow and need to send class corresponding to the various scenes of network request and follow the above-mentioned net realized in advance
Network request protocol or network request interface.Needing to send class corresponding to the various scenes of network request in turn can be respectively at it
The universal method extracted in network request agreement or network request interface is implemented in class.
It should be noted that the network request under different exploitation environment and different development languages, for encapsulation
The specific implementation form of method can be different.For example, under some development languages agreement (Protocol) can be passed through
To encapsulate certain methods.Under some development languages, certain methods can be encapsulated by interface (Interface).
Step 203, call its corresponding for sending the method for target network request to send mesh by identified class
Mark network request.
In the present embodiment, identified class can directly be utilized to call its corresponding for sending target network request
Method, when being executed, identified class will call the method for sending target network request that it is implemented naturally, from
And realize the transmission of target network request.
Optionally, it then follows network request agreement or the class of network request interface directly can call its specific implementation using class
Network request agreement or network request interface defined in method, without being called by example.
In some optional implementations of the present embodiment, network request collection may include being used to indicate to hand over server-side
Mutual network request.Generally, the network request of many transmissions is all sent to server-side, can also further receive later
Server-side is directed to the response message for receiving network request.
For example, being used to indicate the network request interacted with server-side may include being used to indicate from server-side to obtain data
Network request.As an example, network request may include being used to indicate the network request for obtaining comment information from server-side.Network
Request also may include being used to indicate the network request that newest pushed information is obtained from server-side.
In some optional implementations of the present embodiment, network request collection may include being used to indicate and target data
The network request of library interaction.Wherein, target database can refer to the database connecting with above-mentioned executing subject.
For example, being used to indicate the network request interacted with target database may include being used to indicate from target database to obtain
Access evidence.As an example, the data of the network request institute request sent are stored in target database.
In some optional implementations of the present embodiment, target database may include local data base.Some
In the case of, data be that can store in the local of above-mentioned executing subject.For example, above-mentioned executing subject can locally be installed
There is local data base.In another example above-mentioned executing subject has some data in local cache in some cases.
In some optional implementations of the present embodiment, it then follows network request agreement or the class of network request interface can
To include first object class and the second target class.Wherein, network request agreement may be implemented in first object class or network request connects
The method for sending network request encapsulated in mouthful is the network request interacted for sending instruction with server-side.Second target
Class realizes that the method for sending network request encapsulated in network request agreement or network request interface is to indicate for sending
The network request interacted with target database.Wherein, target database can refer to the database connecting with above-mentioned executing subject.It can
Selection of land, target database can be local data base.
Wherein, the corresponding class of different scenes for needing to send network request can follow network request agreement or network is asked
Seek interface.At this time, it then follows network request agreement or the class of network request interface require to realize that network request agreement or network are asked
The method for sending network request encapsulated in interface is sought, but can be different in specific implementation.For example, some classes can
To be implemented as the network request interacted for sending instruction with server-side, some classes can be implemented as referring to for sending
Show the network request interacted with target database.
For example, being packaged with the method for the new displaying information of request in network request agreement or network request interface.Have
The class for following network request agreement or network request interface can implement the side of the new displaying information of this request
Method is the method that request obtains new displaying information from server-side.And some follows network request agreement or network request interface
The method that class can implement the new displaying information of this request is that request obtains new displaying letter from local data base
The method of breath.
The Public method that request is sent under different scenes is extracted by network request agreement or network request interface, by following
Network request agreement or the class of network request interface go to implement corresponding method according to its corresponding application scenarios, further
Promote the convenience for sending network request.
It is one of the application scenarios of the method according to the present embodiment for sending network request with continued reference to Fig. 3, Fig. 3
Schematic diagram 300.In the application scenarios of Fig. 3, terminal device 301 is detecting that user clicks " adding of showing on video page
Carry more " button when, i.e. triggering sends network request to obtain more videos.
Since network request to be sent is used to obtain more videos that the current video page is shown, it is to be sent
The object of network request is the corresponding object of the current video page.The relevant treatment logic of video page is by the video write in advance
Class realizes that the relevant treatment logic of articles page is realized by the article class 303 write in advance.And video class and article class are all abided by
Follow the network request agreement 304 write in advance.Wherein, video page and articles page can be encapsulated in network request agreement 304
The universal method of the various network requests sent, and have in network request agreement 304 in video class 302 and article class 303 and seal
The specific implementation of each method of dress.
For example, the method for the more page presentation information of request can be packaged in network request agreement 304, it is right
Ying Di can implement the method for the more page presentation information of request to obtain more multi-page in video class 302
Show video.It is more to obtain that the method for the more page presentation information of request can be implemented in article class 303
Page presentation article.
Later, the network request for the more videos of request of loading can be called directly by the corresponding video class of video page
Method sends network request to realize to server 305.Later, server 305 can be according to the network request received, to end
End equipment 301 returns to more videos to be presented.
The method provided by the above embodiment of the disclosure is by the way that the general of different types of network request some to be used for
The method for sending network request is packaged into agreement or interface, then the class as corresponding to the different scenes for needing to send network request
Packaged agreement or interface are all followed, so that it is all inevitable real to need to send class corresponding to the different scenes of network request
The method that network request is sent defined in packaged agreement or interface is showed.Therefore, it needs to send network specifically and asks
Under the scene asked, can the class as belonging to the object of network request to be sent call directly send network request method, so that it may
To realize the transmission of network request, help to promote the convenience for sending network request.
With further reference to Fig. 4, as the realization to method shown in above-mentioned each figure, present disclose provides ask for sending network
The one embodiment 400 for the device asked, the Installation practice is corresponding with embodiment of the method shown in Fig. 2, which specifically may be used
To be applied in various electronic equipments.
As shown in figure 4, the device 400 provided in this embodiment for sending network request includes that user requests determination unit
401, class determination unit 402 and transmission unit 403.
In the present embodiment, in the device 400 for sending network request: it is single that user requests determination unit 401, class to determine
The specific processing of member 402 and transmission unit 403 and its brought technical effect can be respectively with reference to the steps in Fig. 2 corresponding embodiment
Rapid 401, the related description of step 402 and step 403, details are not described herein.
In some optional implementations of the present embodiment, network request collection includes being used to indicate to interact with server-side
Network request.
In some optional implementations of the present embodiment, it then follows the class packet of network request agreement or network request interface
Include first object class and the second target class, wherein first object class is realized to be encapsulated in network request agreement or network request interface
The method for sending network request be for sending the network request that interacts with server-side of instruction, the second target class realization net
The method for sending network request encapsulated in network request protocol or network request interface is for sending instruction and number of targets
According to the network request of library interaction.
In some optional implementations of the present embodiment, target database includes local data base.
The device provided by the above embodiment of the disclosure requests determination unit 401 to determine whether to detect use by user
User's request of target network request is sent in instruction, wherein target network request belongs to preset network request collection;Class determines
Unit 402 determines class belonging to the object of target network request to be sent, wherein institute in response to confirmly detecting user's request
Determining class follows network request agreement or network request interface, wherein network request agreement or network request interface are for sealing
The method for filling the network request for sending network request concentration;Transmission unit 403 calls its corresponding by identified class
For sending the method for target network request to send target network request, the convenient of network request is sent to help to be promoted
Property.
Below with reference to Fig. 5, it illustrates the electronic equipment that is suitable for being used to realize embodiment of the disclosure, (example is as shown in figure 1
Terminal device) 500 structural schematic diagram.Terminal device in embodiment of the disclosure can include but is not limited to such as move electricity
Words, laptop, digit broadcasting receiver, PDA (personal digital assistant), PAD (tablet computer), PMP (portable multimedia
Player), the mobile terminal and such as number TV, desktop computer etc. of car-mounted terminal (such as vehicle mounted guidance terminal) etc.
Fixed terminal.Terminal device shown in Fig. 5 is only an example, function to embodiment of the disclosure and should not use model
Shroud carrys out any restrictions.
As shown in figure 5, electronic equipment 500 may include processing unit (such as central processing unit, graphics processor etc.)
501, random access can be loaded into according to the program being stored in read-only memory (ROM) 502 or from storage device 508
Program in memory (RAM) 503 and execute various movements appropriate and processing.In RAM 503, it is also stored with electronic equipment
Various programs and data needed for 500 operations.Processing unit 501, ROM 502 and RAM503 are connected with each other by bus 504.
Input/output (I/O) interface 505 is also connected to bus 504.
In general, following device can connect to I/O interface 505: including such as touch screen, touch tablet, keyboard, mouse, taking the photograph
As the input unit 506 of head, microphone, accelerometer, gyroscope etc.;Including such as liquid crystal display (LCD), loudspeaker, vibration
The output device 507 of dynamic device etc.;Storage device 508 including such as tape, hard disk etc.;And communication device 509.Communication device
509, which can permit electronic equipment 500, is wirelessly or non-wirelessly communicated with other equipment to exchange data.Although Fig. 5 shows tool
There is the electronic equipment 500 of various devices, it should be understood that being not required for implementing or having all devices shown.It can be with
Alternatively implement or have more or fewer devices.Each box shown in Fig. 5 can represent a device, can also root
According to needing to represent multiple devices.
Particularly, in accordance with an embodiment of the present disclosure, it may be implemented as computer above with reference to the process of flow chart description
Software program.For example, embodiment of the disclosure includes a kind of computer program product comprising be carried on computer-readable medium
On computer program, which includes the program code for method shown in execution flow chart.In such reality
It applies in example, which can be downloaded and installed from network by communication device 509, or from storage device 508
It is mounted, or is mounted from ROM 502.When the computer program is executed by processing unit 501, the implementation of the disclosure is executed
The above-mentioned function of being limited in the method for example.
It is situated between it should be noted that computer-readable medium described in embodiment of the disclosure can be computer-readable signal
Matter or computer readable storage medium either the two any combination.Computer readable storage medium for example can be with
System, device or the device of --- but being not limited to --- electricity, magnetic, optical, electromagnetic, infrared ray or semiconductor, or it is any more than
Combination.The more specific example of computer readable storage medium can include but is not limited to: have one or more conducting wires
Electrical connection, portable computer diskette, hard disk, random access storage device (RAM), read-only memory (ROM), erasable type are programmable
Read-only memory (EPROM or flash memory), optical fiber, portable compact disc read-only memory (CD-ROM), light storage device, magnetic are deposited
Memory device or above-mentioned any appropriate combination.In embodiment of the disclosure, computer readable storage medium, which can be, appoints
What include or the tangible medium of storage program that the program can be commanded execution system, device or device use or and its
It is used in combination.And in embodiment of the disclosure, computer-readable signal media may include in a base band or as carrier wave
The data-signal that a part is propagated, wherein carrying computer-readable program code.The data-signal of this propagation can be adopted
With diversified forms, including but not limited to electromagnetic signal, optical signal or above-mentioned any appropriate combination.Computer-readable signal is situated between
Matter can also be any computer-readable medium other than computer readable storage medium, which can be with
It sends, propagate or transmits for by the use of instruction execution system, device or device or program in connection.Meter
The program code for including on calculation machine readable medium can transmit with any suitable medium, including but not limited to: electric wire, optical cable,
RF (radio frequency) etc. or above-mentioned any appropriate combination.
Above-mentioned computer-readable medium can be included in above-mentioned terminal;It is also possible to individualism, and it is unassembled
Enter in the terminal.Above-mentioned computer-readable medium carries one or more program, when said one or multiple program quilts
When the terminal executes, so that the terminal: determine whether to detect that being used to indicate the user for sending target network request requests,
In, target network request belongs to preset network request collection;In response to confirmly detecting user's request, target network to be sent is determined
Class belonging to the object of network request, wherein identified class follows network request agreement or network request interface, wherein network
The method that request protocol or network request interface are used to be packaged for sending the network request that network request is concentrated;By being determined
Class call its it is corresponding for send target network request method with send target network request.
The behaviour for executing embodiment of the disclosure can be write with one or more programming languages or combinations thereof
The computer program code of work, described program design language include object oriented program language-such as Java,
Smalltalk, C++ further include conventional procedural programming language-such as " C " language or similar program design language
Speech.Program code can be executed fully on the user computer, partly be executed on the user computer, as an independence
Software package execute, part on the user computer part execute on the remote computer or completely in remote computer or
It is executed on server.In situations involving remote computers, remote computer can pass through the network of any kind --- packet
Include local area network (LAN) or wide area network (WAN) --- it is connected to subscriber computer, or, it may be connected to outer computer (such as
It is connected using ISP by internet).
Flow chart and block diagram in attached drawing are illustrated according to the system of the various embodiments of the disclosure, method and computer journey
The architecture, function and operation in the cards of sequence product.In this regard, each box in flowchart or block diagram can generation
A part of one module, program segment or code of table, a part of the module, program segment or code include one or more use
The executable instruction of the logic function as defined in realizing.It should also be noted that in some implementations as replacements, being marked in box
The function of note can also occur in a different order than that indicated in the drawings.For example, two boxes succeedingly indicated are actually
It can be basically executed in parallel, they can also be executed in the opposite order sometimes, and this depends on the function involved.Also it to infuse
Meaning, the combination of each box in block diagram and or flow chart and the box in block diagram and or flow chart can be with holding
The dedicated hardware based system of functions or operations as defined in row is realized, or can use specialized hardware and computer instruction
Combination realize.
Being described in unit involved in embodiment of the disclosure can be realized by way of software, can also be passed through
The mode of hardware is realized.Described unit also can be set in the processor, for example, can be described as: a kind of processor
Determination unit, class determination unit and transmission unit are requested including user.Wherein, the title of these units is not under certain conditions
The restriction to the unit itself is constituted, for example, user requests determination unit to be also described as " determining whether to detect and being used for
It indicates to send the unit that the user of target network request requests ".
Above description is only the preferred embodiment of the disclosure and the explanation to institute's application technology principle.Those skilled in the art
Member it should be appreciated that embodiment of the disclosure involved in invention scope, however it is not limited to the specific combination of above-mentioned technical characteristic and
At technical solution, while should also cover do not depart from foregoing invention design in the case where, by above-mentioned technical characteristic or its be equal
Feature carries out any combination and other technical solutions for being formed.Such as disclosed in features described above and embodiment of the disclosure (but
It is not limited to) technical characteristic with similar functions is replaced mutually and the technical solution that is formed.