How to Use ixmlhttprequest in Delphi to submit a request with parameters in post Mode

Source: Internet
Author: User

Http://blog.sina.com.cn/s/blog_51a71c010100gbua.html

(The server is Java, encoding UTF-8, return data encoding UTF-8; Data Exchange Format JSON.

Procedure tloginform. loginbtnclick (Sender: tobject );
VaR
 Jo: isuperobject; // JSON Interface
 Req: ixmlhttprequest;
 URL: widestring; // URL to be accessed

 Params: string; // data to be submitted
Begin
 // URL to be accessed
 URL: = 'HTTP: // localhost/wuliu/servlet/login ';

 {Req: = coxmlhttp. Create; // use this name for delphi2010}
 // Instantiate ixmlhttprequest
 Req: = coxmlhttprequest. Create;
 // Call the Open Method
 Req. Open ('post', URL, false, emptyparam, emptyparam );
 // Set post Parameters
 Req. setRequestHeader ('content-type', 'application/X-WWW-form-urlencoded ');
 // Req. setRequestHeader ('content-length', inttostr (length (sparams )));

 // Submit data
 Params: = 'account = Hello everyone & Password = good ';

 // Send the request
 Req. Send (Params );

 Showmessage (req. responsetext );

 // JO: = So (req. responsetext );

End;

The above is my implementation method. You can submit the required parameters to the server correctly. Note Req. setRequestHeader ('content-type', 'application/X-WWW-form-urlencoded'). This parameter is required for the post parameter data. Params: = 'account = Hello everyone & Password = good'; it is the parameter data to be submitted, type: string. These are ready. Use Req. Send (Params); submit the data to the server; the obtained data is Req. responsetext );

If you have any questions, please contact: sunylat@gmail.com

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.