Based on Simon Wittber's UnityWeb code (http://code.google.com/p/unityweb/).
UnityHTTP falls under the GPL due to its basis on Simon Wittber's UnityWeb code, which is licensed under the GPL.
You should be aware of this license and determine if it is acceptable for your project.
This is a TcpClient-based HTTP library for use in Unity. It should work in both the standalone player and in the web player.
It also has convenience methods for working with JSON.
IEnumerator example:
publicIEnumeratorSomeRoutine(){HTTP.RequestsomeRequest=newHTTP.Request("get","http://someurl.com/somewhere");someRequest.Send();while(!someRequest.isDone){yieldreturnnull;}// parse some JSON, for example:JSONObjectthing=newJSONObject(request.response.Text);}Closure-style (does not need to be in a coroutine):
HTTP.RequestsomeRequest=newHTTP.Request("get","http://someurl.com/somewhere");someRequest.Send((request)=>{// parse some JSON, for example:JSONObjectthing=newJSONObject(request.response.Text);});Post request using form data:
WWWFormform=newWWWForm();form.AddField("something","yo");form.AddField("otherthing","hey");HTTP.RequestsomeRequest=newHTTP.Request("post","http://someurl.com/some/post/handler",form);someRequest.Send((request)=>{// parse some JSON, for example:boolresult=false;Hashtablething=(Hashtable)JSON.JsonDecode(request.response.Text,refresult);if(!result){Debug.LogWarning("Could not parse JSON response!");return;}});Post request using JSON:
Hashtabledata=newHashtable();data.Add("something","hey!");data.Add("otherthing","YO!!!!");// When you pass a Hashtable as the third argument, we assume you want it send as JSON-encoded// data. We'll encode it to JSON for you and set the Content-Type header to application/jsonHTTP.RequesttheRequest=newHTTP.Request("post","http://someurl.com/a/json/post/handler",data);theRequest.Send((request)=>{// we provide Object and Array convenience methods that attempt to parse the response as JSON// if the response cannot be parsed, we will return null// note that if you want to send json that isn't either an object ({...}) or an array ([...])// that you should use JSON.JsonDecode directly on the response.Text, Object and Array are// only provided for convenienceHashtableresult=request.response.Object;if(result==null){Debug.LogWarning("Could not parse JSON response!");return;}});If you want to make a request while not in Play Mode (e. g. from a custom Editor menu command or wizard), you must use the Request synchronously, since Unity's main update loop is not running. The call will block until the response is available.
Hashtabledata=newHashtable();data.Add("something","hey!");data.Add("otherthing","YO!!!!");HTTP.RequesttheRequest=newHTTP.Request("post","http://someurl.com/a/json/post/handler",data);theRequest.synchronous=true;theRequest.Send((request)=>{EditorUtility.DisplayDialog("Request was posted.",request.response.Text,"Ok");});