I am trying to make a POST request to restful web APIs in Unity.
The header would be Content-Type: application/json
An example of the raw data i
try {
string url_registerEvent = "http://demo....?parameter1=" parameter1value"¶meter2="parameter2value;
WebRequest req = WebRequest.Create (url_registerEvent);
req.ContentType = "application/json";
req.Method = "SET";
//req.Credentials = new NetworkCredential ("connect10@gmail.com", "connect10api");
HttpWebResponse resp = req.GetResponse () as HttpWebResponse;
var encoding = resp.CharacterSet == ""
? Encoding.UTF8
: Encoding.GetEncoding (resp.CharacterSet);
using (var stream = resp.GetResponseStream ()) {
var reader = new StreamReader (stream, encoding);
var responseString = reader.ReadToEnd ();
Debug.Log ("Result :" + responseString);
//JObject json = JObject.Parse(str);
}
} catch (Exception e) {
Debug.Log ("ERROR : " + e.Message);
}