我有一个api,在某些事件中被调用。 api也适用于Web平台和编辑器,但不适用于iOS设备。这是我的代码,我打电话给api:
string data = "{'UserName':'myUserName'," + "'Password':'myPass'}"; var encoding = new System.Text.UTF8Encoding(); var header = new Hashtable(); header.Add("content-type", "application/json"); header.Add("content-length", data.Length); Debug.Log("Time To Hit the api"); ////Now below is the api I am hitting//// WWW responseToken = new WWW(someLink, encoding.GetBytes(data), header); yield return responseToken; Debug.Log("Now get the response");
我需要这个api才能在iOS设备上运行。在iOS设备上运行此代码时,它会打印日志语句“Time To Hit the api”,但它永远不会打印“Now get the response”日志。
请在这里帮助我,我在这里做错了什么?
答案 0 :(得分:0)
您可以使用WWWForm吗? 我用它并且工作正常。
参见示例:
// Create a form object for sending high score data to the server
var form = new WWWForm();
// Assuming the perl script manages high scores for different games
form.AddField( "game", "MyGameName" );
// The name of the player submitting the scores
form.AddField( "playerName", playName );
// The score
form.AddField( "score", score );
// Create a download object
var download = new WWW( someLink, form );
// Wait until the download is done
yield download;
if(download.error) {
print( "Error downloading: " + download.error );
return;
} else {
// show the highscores
Debug.Log(download.text);
}