- Home /
Question by
BlackGOD12 · Dec 31, 2021 at 11:56 AM ·
serverjsonapijsonfx
Can anyone tell me what's wrong in this, I try to post values to API
1 SCRIPT
{
Dictionary<string, string> formdata = new Dictionary<string, string>();
formdata.Add("fb_token", ID);
formdata.Add("coins", PlayerPrefs.GetInt("Coins_Collected").ToString());
formdata.Add("gems", PlayerPrefs.GetInt("Gems_Collected").ToString());
yield return (StartCoroutine(_networkManager.PostGameData("https://www.duelofthieves.com/production/public/api/v1/store/updategems", formdata, Application.persistentDataPath + "/" + Constant.FileLocations.JsonGameLocation)));
}
{
Dictionary<string, string> formdata = new Dictionary<string, string>();
formdata.Add("fb_token", ID);
formdata.Add("coins", PlayerPrefs.GetInt("Coins_Collected").ToString());
formdata.Add("gems", PlayerPrefs.GetInt("Gems_Collected").ToString());
yield return (StartCoroutine(_networkManager.PostGameData("https://www.duelofthieves.com/production/public/api/v1/street", formdata, Application.persistentDataPath + "/" + Constant.FileLocations.JsonGameLocation)));
}
SCRIPT FOR POSTING
public IEnumerator PostGameData(string URL, Dictionary formData, string fileLocation)
{
WWWForm formdata = new WWWForm();
foreach (KeyValuePair<string, string> kvpair in formData)
{
formdata.AddField(kvpair.Key, kvpair.Value);
}
using (UnityWebRequest UWR = UnityWebRequest.Post(URL, formdata))
{
UWR.downloadHandler = new DownloadHandlerBuffer();
yield return UWR.SendWebRequest();
yield return new WaitUntil(() => UWR.isDone);
if (UWR.responseCode != 200)
{
Debug.Log("Erro has occured " + System.Environment.NewLine + UWR.error);
}
else
{
yield return new WaitUntil(() => UWR.downloadHandler.isDone);
System.IO.File.WriteAllText(fileLocation, UWR.downloadHandler.text);
Debug.Log("Uploaded");
}
UWR.Dispose();
}
}
The first dictionary values post prefect, but the second posting values return error can anyone tell me what is the actual problem. Both links are perfect they works perfect on postman.
Comment
Your answer
Follow this Question
Related Questions
How do I send data to a cloud server like Amazon EC2? 1 Answer
Cannot cast from source type to destination type Json 0 Answers
Save and Load JSON Data to and from Webserver, Performance Question 0 Answers
Unity as server side? 0 Answers
How to connect unity to MySQL (MariaDB) API, Unity ver 2019.4? 0 Answers