Summary of the invention
The flexibility of solicited message being decoded in order to improve server, and avoid producing mess code, the embodiment of the present invention provides a kind of method that solicited message is decoded and device.Described technical scheme is as follows:
On the one hand, provide a kind of method that solicited message is decoded, described method comprises:
Receive solicited message, described request information comprises request path, query string and list content;
Obtain the coded system in described request path, according to the coded system in described request path, decoded in described request path, and obtain respectively query string and list content according to decoded request path;
Obtain respectively the coded system of described query string and list content, and according to the coded system of described query string and list content, described query string and list content are decoded;
According to decoded solicited message, obtain response message;
Obtain coded system, according to the coded system getting, described response message is encoded;
Return to response message after coding and the coded system of employing.
On the other hand, provide a kind of device that solicited message is decoded, described device comprises:
Receiver module, for receiving solicited message, described request information comprises request path, query string and list content;
The first acquisition module, for obtaining the coded system in described request path;
The first decoder module, decodes to described request path for the coded system in the described request path that gets according to described the first acquisition module;
The second acquisition module, for obtaining respectively query string and list content according to the decoded request path of described the first decoder module;
The 3rd acquisition module, for obtaining respectively described query string that described the second acquisition module gets and the coded system of list content;
The second decoder module, decodes to described query string and list content for the query string that gets according to described the 3rd acquisition module and the coded system of list content;
The 4th acquisition module, for obtaining response message according to decoded solicited message;
The 5th acquisition module, for obtaining coded system;
Coding module, the response message described the 4th acquisition module being got for the coded system getting according to described the 5th acquisition module is encoded;
Return to module, for returning to response message after described coding module coding and the coded system of employing.
The beneficial effect that the technical scheme that the embodiment of the present invention provides is brought is:
By obtaining respectively the coded system of request path, query string and the list content various piece of solicited message, and according to the coded system getting, solicited message is decoded, thereby can determine different decoding processes according to different coded systems, and then improve the flexibility of decoding; In addition, because the coded system according to solicited message is decoded to it, thereby can guarantee decoding correctness, avoid producing mess code.
Embodiment
For making the object, technical solutions and advantages of the present invention clearer, below in conjunction with accompanying drawing, embodiment of the present invention is described further in detail.
Embodiment 1
Referring to Fig. 1, the embodiment of the present invention provides a kind of method that solicited message is decoded, and the method flow process is specific as follows:
Step 101, receives solicited message, and this solicited message comprises request path, query string and list content;
Step 102, obtains the coded system of request path, according to the coded system of request path, request path is decoded, and obtains respectively query string and list content according to decoded request path;
Step 103, obtains respectively the coded system of query string and list content, and according to the coded system of query string and list content, query string and list content is decoded.
The method that the embodiment of the present invention provides, by obtaining respectively the coded system of request path, query string and the list content various piece of solicited message, and according to the coded system getting, solicited message is decoded, thereby can determine different decoding processes according to different coded systems, and then improve the flexibility of decoding; In addition, because the coded system according to solicited message is decoded to it, thereby can guarantee decoding correctness, avoid producing mess code.
Embodiment 2
The embodiment of the present invention provides a kind of method that solicited message is decoded, the method is by obtaining the coded system of solicited message, and according to the coded system of solicited message, it is decoded, thereby can be correctly decoded solicited message, avoid producing mess code.For convenience of explanation, the embodiment of the present invention receives with server HTML (Hypertext Markup Language) (the Hyper Text Transfer Protocol that browser sends, HTTP) solicited message, and this HTTP solicited message is decoded as to example, the method that the embodiment of the present invention is provided is elaborated.Referring to Fig. 2, method flow is specific as follows:
Step 201, receives the HTTP solicited message that browser sends;
For this step, after browser and server connects, server receives the HTTP solicited message of browser transmission can pass through existing techniques in realizing, and the embodiment of the present invention does not limit concrete receive mode.
Wherein, HTTP solicited message is generally divided into request path, query string and list content three parts.The HTTP solicited message that the browser of take sends to server comprise " www.apusic.com/index.jsp? key1=Chinese character " URL(uniform resource locator) (Uniform/Universal Resource Locator, URL) and content of pages corresponding to this URL " " Chinese "/> " is example to <input name=" test2 " type=" text " value=.Wherein, " www.apusic.com/index.jsp " is request path, and " key1=Chinese character " is query string, and " " Chinese "/> " is list content to <input name=" test2 " type=" text " value=.That is to say, in URL symbol "? " part is above request path; In URL symbol "? " part is below query string.While using Post method to submit data to, the body part of HTTP request is list content.In practical application, the HTTP solicited message that browser sends to server also may only include request path and query string two parts, and list content is empty.As user inputs URL address by browser, in the HTTP solicited message that browser sends, only comprise request path and query string.The embodiment of the present invention only be take HTTP solicited message that browser sends to server and is comprised that request path, query string and list content describe as example.
The HTTP solicited message that server receives sends after browser coding, when browser is encoded to HTTP solicited message, to the various piece of HTTP solicited message, can adopt a kind of coded system.Yet, due to reasons such as browser place client-side program are numerous and diverse, cause being difficult to three parts in HTTP solicited message to adopt same coded systems to encode.Therefore,, when HTTP solicited message is encoded, conventionally adopt Multi-encoding mode.For example the request path of HTTP solicited message adopts coded system A, and query string adopts coded system B, and list content adopts coded system C, and this HTTP solicited message has adopted altogether three kinds of coded systems.The embodiment of the present invention does not limit the specific coding mode of the request path of HTTP solicited message, query string and list content, for example, the coded system C of the coded system A of request path, the coded system B of query string and list content can be Chinese character code mode (GB2312, GBK, UTF-8), Chinese-traditional coded system (big5) or Japanese coded system (shift_jis) etc.
The specific coding mode that the embodiment of the present invention does not adopt browser does not limit, and the browser of only take adopts situation that different coded systems encodes to describe as example to the various piece of HTTP solicited message.
Step 202, obtains the coded system of the HTTP solicited message receiving;
Particularly, for request path, query string and the list content various piece of HTTP solicited message, adopt the situation of different coding mode, still the request path with HTTP solicited message adopts coded system A, and query string adopts coded system B, and it is that example describes that list content adopts coded system C.When obtaining the coded system of HTTP solicited message, the embodiment of the present invention is divided into HTTP solicited message request path, query string and list content three part differentiated treatment equally, and obtains respectively the coded system A of request path, the coded system C of the coded system B of query string and list content.While specifically obtaining, first server obtains the coded system A of request path, according to the coded system A getting, request path is decoded, according to decoded request path, obtain query string and list content again, and after obtaining the coded system B of query string and the coded system C of list content, query string and list content are decoded respectively.Wherein, while obtaining the coded system A of request path, include but not limited to following two kinds of modes:
User's configuration, user has configured the coded system A of request path in advance in server, and server configures by inquiring user, can get the coded system of request path.
Automatically identification, server adopts automatic identification algorithm to identify the coded system A of request path.The embodiment of the present invention does not limit the automatic identification algorithm adopting.For example, everyday character frequency identification algorithm etc.For this kind of situation, even if different browsers adopts different coded systems to encode to request path, by automatic identification, server still can obtain the coded system of this request path.
While obtaining the coded system B of query string, except obtaining the coded system of query string by the mode of above-mentioned user's configuration and identification automatically, can also obtain by the mode of code appointment the coded system of query string.For example, user has configured the coded system B of query string in server, server configures the coded system B that obtains query string by inquiring user, or server automatically identifies the coded system B of query string, or query string code has been specified the coded system B of query string, server, by obtaining query string code, obtains the coded system B of query string.
While obtaining the coded system C of list content, can adopt equally that user configures, identification and the mode of code appointment automatically, be the coded system C that user has configured list content in server, or server automatically identifies the coded system C of list content, or list content code has been specified the coded system C of list content.
For the obtain manner of above-mentioned user configuration and code appointment, no matter be to obtain request path, still obtain query string, or obtain list content, be all in the situation that can obtain its correct coded system and adopt.And in practical application, the coded system of user's configuration and code appointment also exists and request path, or query string, or the different situation of actual coding mode of list content.For fear of above-mentioned situation, guarantee to get correct coded system, the embodiment of the present invention has proposed user's configuration and code to specify the mode shielding.By adopting, user's configuration and code appointment are shielded, even if server exists user to configure or code is specified, still adopt the mode of automatic identification to obtain the coded system of HTTP solicited message, thereby for the HTTP solicited message through any coded system coding, server all can correctly obtain its coded system.
Step 203, decodes to HTTP solicited message according to the coded system getting.
For this step, the coded system while encoding with HTTP solicited message due to the coded system getting is identical.Therefore,, when HTTP solicited message being decoded according to the coded system getting, can not produce mess code.
The process of so far, HTTP solicited message being decoded finishes.After HTTP solicited message is decoded, the method that the embodiment of the present invention provides also comprises the steps.
Step 204, obtains response message according to decoded HTTP solicited message, and the response message after coding and the coded system of employing are returned to browser;
Particularly, the embodiment of the present invention does not limit obtaining the mode of response message.In practical application, server can arrive corresponding match information according to decoded list content search, and this match information is the response message of HTTP solicited message.About how this response message being encoded, the embodiment of the present invention is not done concrete restriction, includes but not limited to adopt user to configure, and several modes such as code appointment and automatically identification are obtained the coded system of response message.While specifically obtaining the coded system of response message, can configure user, code is specified and automatically in the mode such as identification random selection a kind of, can also select by the mode of priority is set, the embodiment of the present invention, to selecting obtain manner to limit, does not limit the mode of priority is set equally.
For example, code appointment, user's configuration and automatic identification are established to priority from high to low successively,, when response message is encoded, first judge whether to exist the coded system of code appointment, if exist, adopt the coded system of code appointment to encode; If there is no, then judge whether to exist user configured coded system, when there is user configured coded system, adopt user configured coded system to encode, otherwise, adopt the coded system automatically identifying to encode to response message.
No matter which kind of coded system server adopts encode to response message, and server, by the coded system of employing and response message are together sent to browser, can guarantee that browser is correctly decoded, thereby avoids the generation of mess code.During specific implementation, server can arrange head response by obtaining Http Writer, and by head response, the coded system of employing and response message is returned to browser.
Browser receives response message, directly according to the coded system comprising in this response message, response message is decoded, and do not need to identify the coded system of response message, thereby browser can not produce mess code.
The method that solicited message is decoded that the embodiment of the present invention provides, by obtaining respectively the coded system of request path, query string and the list content various piece of HTTP solicited message, and according to the coded system getting, the various piece of HTTP solicited message is decoded respectively, guaranteed to be correctly decoded HTTP solicited message, thereby there will not be mess code; Again due to the various piece of HTTP solicited message has been carried out to differentiated treatment, and determine corresponding decoding process according to the coded system of the various piece of HTTP solicited message, thereby improved the flexibility that server is decoded to HTTP solicited message, and when the various piece of HTTP solicited message is carried out to differentiated treatment, by shielding user configuration and code, specify, and adopt the mode of automatically identifying to obtain the coded system of HTTP solicited message, can guarantee the HTTP solicited message through any coded system coding to be correctly decoded; In addition, server is after obtaining response message and it is encoded, by response message and coded system thereof after coding are returned to browser, browser can be correctly decoded the response message after encoding according to this coded system, thereby further avoid generation mess code.
Embodiment 3
Referring to Fig. 3, the embodiment of the present invention provides a kind of device that solicited message is decoded, and this device comprises:
Receiver module 301, for receiving solicited message, solicited message comprises request path, query string and list content;
The first acquisition module 302, for obtaining the coded system of request path;
The first decoder module 303, decodes to request path for the coded system of the request path that gets according to the first acquisition module 302;
The second acquisition module 304, for obtaining respectively query string and list content according to the decoded request path of the first decoder module 303;
The 3rd acquisition module 305, for obtaining respectively query string that the second acquisition module 304 gets and the coded system of list content;
The second decoder module 306, decodes to query string and list content for the query string that gets according to the 3rd acquisition module 305 and the coded system of list content.
Wherein, the first acquisition module 302, specifically for obtaining the coded system of user configured request path, or obtains the coded system of the request path automatically identifying;
Referring to Fig. 4, the 3rd acquisition module 305, specifically comprises:
First module 3051, specifically for obtaining the coded system of user configured query string, or obtains the coded system of the query string automatically identifying, or obtains the coded system of the query string of code appointment;
Second unit 3052, specifically for obtaining the coded system of user configured list content, or obtains the coded system of the list content automatically identifying, and obtains the coded system of the list content of code appointment.
Referring to Fig. 5, this device also comprises:
The 4th acquisition module 307, for obtaining response message according to decoded solicited message;
The 5th acquisition module 308, for obtaining coded system;
Coding module 309, the response message the first acquisition module 303 being got for the coded system getting according to the 5th acquisition module 308 is encoded;
Return to module 310, for returning to response message after coding module 309 coding and the coded system of employing.
Particularly, the 5th acquisition module 308, specifically for obtaining user configured coded system, or obtains the coded system of code appointment, or obtains the coded system of automatic identification.
The device that solicited message is decoded that the embodiment of the present invention provides, by obtaining the coded system of solicited message, and according to the coded system getting, solicited message is decoded, thereby can determine different decoding processes according to different coded systems, and then improve the flexibility of decoding; And because the coded system according to solicited message is decoded to it, thus can guarantee decoding correctness, avoid producing mess code.In addition, server is after obtaining response message and it is encoded according to solicited message, by returning to response message after coding and the coded system of response message, the equipment that receives the response message after this coding can be correctly decoded the response message after encoding according to this coded system, thereby further avoid generation mess code.
It should be noted that: the device that solicited message is decoded that above-described embodiment provides is when decoding to solicited message, only the division with above-mentioned each functional module is illustrated, in practical application, can above-mentioned functions be distributed and by different functional modules, completed as required, the internal structure that is about to device is divided into different functional modules, to complete all or part of function described above.In addition, the device that solicited message is decoded that above-described embodiment provides belongs to same design with the embodiment of the method that solicited message is decoded, and its specific implementation process refers to embodiment of the method, repeats no more here.
All or part of content in the technical scheme that above embodiment provides can realize by software programming, and its software program is stored in the storage medium can read, storage medium for example: the hard disk in computer, CD or floppy disk.
The foregoing is only preferred embodiment of the present invention, in order to limit the present invention, within the spirit and principles in the present invention not all, any modification of doing, be equal to replacement, improvement etc., within all should being included in protection scope of the present invention.