Content-Type: Application/X-WWW-form-urlencoded

Source: Internet
Author: User

Accept XML from third-party post. If Content-Type: Application/X-WWW-form-urlencoded is not set. You can use the stream to parse
The Code is as follows:

Java code
  1. Bufferedreader in = new bufferedreader (New inputstreamreader (httpservletrequest. getinputstream ()));
  2. String S = "";
  3. Stringbuffer sb = new stringbuffer ();
  4. While (S = in. Readline ())! = NULL ){
  5. SB. append (s );
  6. }
  7. // Parse XML using dom
  8. Documentbuilderfactory buildfactory = documentbuilderfactory. newinstance ();
  9. Documentbuilder build = buildfactory. newdocumentbuilder ();
  10. Document document = build. parse (httpservletrequest. getinputstream (), "UTF-8 ");
  11. Nodelist = Document. getelementsbytagname ("Mo ");
  12. For (INT I = 0; I <nodelist. getlength (); I ++ ){
  13. Longcodearray. Add (document. getelementsbytagname ("longcode"). Item (I). getfirstchild (). getnodevalue (). substring (1 ));
  14. Messagearray. Add (document. getelementsbytagname ("message"). Item (I). getfirstchild (). getnodevalue ());
  15. }

 

 

If you have set Content-Type: Application/X-WWW-form-urlencoded, you need to go to parmmetermap to get it.

Java code
  1. List <string> longcodearray = new arraylist <string> ();
  2. List <string> messagearray = new arraylist <string> ();
  3. Try {
  4. Createlog log = new createlog ();
  5. Httpservletrequest = This. gethttpservletrequest ();
  6. String keyandvalue = "";
  7. String key = "";
  8. String value = "";
  9. Iterator <string> it = httpservletrequest. getparametermap (). keyset (). iterator ();
  10. While (it. hasnext ()){
  11. Key = it. Next ();
  12. Value = (object []) (httpservletrequest. getparametermap (). Get (key) [0]. tostring ();
  13. Keyandvalue = Key + "=" + value;
  14. System. Out. println (Key + "=" + value );
  15. }
  16. If (keyandvalue! = NULL ){
  17. // Dom4j to parse XML strings
  18. Document document = incluenthelper. parsetext (keyandvalue. tostring ());
  19. Element root = Document. getrootelement ();
  20. List mo = root. Elements ("Mo ");
  21. For (INT I = 0; I <Mo. Size (); I ++ ){
  22. Element longcode = (element) Mo. Get (I). element ("longcode ");
  23. Element message = (element) Mo. Get (I). element ("message ");
  24. Longcodearray. Add (longcode. gettext ());
  25. Messagearray. Add (message. gettext ());
  26. }
  27. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.