Search Unity

how to read data from wwwForm ?

Discussion in 'Getting Started' started by Bui-Thanh, Jan 22, 2016.

  1. Bui-Thanh

    Bui-Thanh

    Joined:
    Nov 22, 2015
    Posts:
    1
    I'm trying to create 1 web server to read the data sent from the client, the client I wrote a function to send
    public void sendToService()
    {
    string url = "http://localhost:64614/api/values";
    WWWForm form = new WWWForm();
    form.AddField("val1", "value1");
    form.AddField ("val2", "value2");
    WWW www = new WWW (url, form);
    StartCoroutine(WaitForRequest(www));
    }
    IEnumerator WaitForRequest(WWW www)
    {
    yield return www;
    // check for errors
    if (www.error == null)
    {
    Debug.Log("WWW Ok!: " + www.text);
    } else {
    Debug.Log("WWW Error: "+ www.error);
    }
    }
    this is my server controler :
    public class ValuesController : ApiController
    {
    [HttpPost]
    public string Set(HttpRequestMessage validatedata)
    {
    //values.val1 = data.val1;
    //values.val2 = data.val2;
    return "SET DATA : val1 = "+values.val1 + " val2 = " + values.val2 + "data = " + validatedata;
    }
    }
    how to read the data transmitted from the client and stored in the variable on the server, thanks a lot