I have a Android App which is via Web Services connected with my ASP.NET WebApi Server. For sending requests I am using AsyncHttpClient
and for passing parameters to the server I use RequestParams
. Now I want to send a complex object that contains a list with other complex objects to my server, and there is the issue. How am I supposed to do that? For simple types, it is pretty easy, since I just need to call parameter.add("paramname", paramvalue);
multiple times on the same parameter name, and on the server side I receive a list. But what should the call look like when my list has complex types so that I receive a list on my server containing these complex types?
Let's say I have a book that contains a list of authors:
class Book {
string title;
int year;
List<Authors> authors;
}
class Author {
string name;
int age;
}
How should I pass a Book (including authors)to my server using Request params (let's assume the data class on the server looks the same)?
I've almost forgot that the server accepts JSON as format.
Thanks
Then you need to convert your complex objects to json object (you can either do it manually or with GSON Libary)
Then you can use library like Google Volley to post your request to server:
Finally add Action method for the request in your api controller
EDIT: for posting JSON via AsyncHttpClient use this: