Basic Application of WWW in Unity

Source: Internet
Author: User

Unity's WWW mainly supports the get and post methods in HTTP. After the get method attaches the request to the URL, the POST method submits the request in form.

The following is information about the unity client:

Using unityengine; using system. collections; public class webmanger: monobehaviour {// use this for initialization void start () {}// update is called once per frame void Update () {} string m_string = "nothing"; void ongui () {GUI. begingroup (New rect (300, screen. height * 0.5f-1,500,200), ""); GUI. label (New rect (10, 10,), m_string); If (GUI. button (New rect (,), "Get Data") {startcoroutin E (igetdata ();} If (GUI. button (New rect (,), "Post Data") {startcoroutine (ipostdata ();} GUI. endgroup ();} ienumerator igetdata () {WWW = new WWW ("http: // localhost: 12063/default. aspx? Name = hometown1986 "); yield return WWW; // wait for the response from the Web server if (www. Error! = NULL) {m_string = www. error; yield return NULL;} m_string = www. text;} ienumerator ipostdata () {system. collections. hashtable headers = new hashtable (); headers. add ("Content-Type", "application/X-WWW-form-urlencoded "); // Save the HTTP header // Save the string as a byte array string data = "Pwd = chinajoy"; byte [] bt = system. text. utf8encoding. utf8.getbytes (data); www WWW = new WWW ("http: // localhost: 12063/default. aspx ", BT, headers); yield Return WWW; If (www. Error! = NULL) {m_string = www. error; yield return NULL;} m_string = www. Text ;}}


Below is how C # handles the server:

Public partial class _ default: system. Web. UI. Page {protected void page_load (Object sender, eventargs e) {// get If (request. querystring ["name"]! = NULL) {response. write ("name:" + request. querystring ["name"]. tostring ();} // post response. write ("Password:" + request. form ["PWD"]); response. end ();}}

 

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.