Data pass using POST method - WebRequest object

倖福魔咒の 提交于 2019-12-12 03:46:28

问题


I want to use POST method to pass data over web server. I want to retrieve data provided by web server in JSON format. I have used following code by referring Unity Manual.

 void Start ()
 {
     StartCoroutine (LoadLoginInfo ());
 }

 IEnumerator LoadLoginInfo ()
 {
     Debug.Log("Load Login Info");

     WWWForm form = new WWWForm ();
     form.AddField ("username", "admin");
     form.AddField ("password", "Admin123#");

     UnityWebRequest www = UnityWebRequest.Post (url, form);
     yield return www.Send();

     if (www.isError) {
         Debug.Log (www.error);
     } else {
         Debug.Log ("Data: " + www.downloadHandler.text);
     }
 }

But after certain amount of wait, I am getting following message in console.

If I try similar thing in browser then it works perfectly.

So what is the correct way to use POST method using WebRequest object?

来源:https://stackoverflow.com/questions/37853659/data-pass-using-post-method-webrequest-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!