1

我有一个在某些事件上调用的 api。该 api 也适用于 Web 平台和 Editor,但不适用于 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”日志。

请在这里帮助我,我在这里做错了什么?

4

1 回答 1

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);
}
于 2014-07-19T23:00:52.367 回答