Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

need help for POST method #5

Closed
Vinita18 opened this issue Dec 8, 2017 · 4 comments
Closed

need help for POST method #5

Vinita18 opened this issue Dec 8, 2017 · 4 comments

Comments

@Vinita18
Copy link

Vinita18 commented Dec 8, 2017

This is my code and I am trying to post gender = "male".
but this code is not working for me.

RestClient.Post<Models.RootObjectData> (url, new
{
gender = "male"
}, (err, res,body) => {
if (err != null) {
EditorUtility.DisplayDialog ("Error", err.Message, "Ok");
} else {
EditorUtility.DisplayDialog ("Success", JsonUtility.ToJson (body, true), "Ok");
}
});

Model Classes:
[Serializable]
public class Data
{
public int timestamp_created;
public int id;
public string gender;
public string access_token;

	public override string ToString(){
		return UnityEngine.JsonUtility.ToJson (this, true);
	}
}

[Serializable]
public class RootObjectData
{
	public bool status;
	public int statusCode;
	public Data data;
	public string message;


	public override string ToString(){
		return UnityEngine.JsonUtility.ToJson (this, true);
	}
}
@jdnichollsc
Copy link
Member

jdnichollsc commented Dec 9, 2017

@Vinita18 Can you attach the log of the error please? I don't know if it's an error from your service and we need to validate that the configuration of CORS works well from the service

@jdnichollsc jdnichollsc added this to To Do in Development Dec 14, 2017
@jdnichollsc
Copy link
Member

Can you attach the response of your service? I need to know what's the JSON returned from your service to check if your code is correct. Closed this issue for the moment, let me know more details to reopen the issue

@jdnichollsc jdnichollsc moved this from To Do to Done in Development Feb 2, 2018
@jdnichollsc
Copy link
Member

@Vinita18 after reviewing with NodeJS as the Backend, we can't send anonymous objects, a Serializable class is required. Example:

[Serializable]
public class ServerResponse {
  public string id;
  public DateTime date;
}
[Serializable]
public class User {
  public string firstName;
  public string lastName;
}
RestClient.Post<ServerResponse>("www.myapi.com/myendpoint", new User {
  firstName = "Juan David",
  lastName = "Nicholls Cardona"
}).Then(response => {
  EditorUtility.DisplayDialog("ID: ", response.id, "Ok");
  EditorUtility.DisplayDialog("Date: ", response.date.ToString(), "Ok");
});

Best regards, Nicholls

@Vinita18
Copy link
Author

Okay. Thanks.
I will try it next time in my code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

No branches or pull requests

2 participants