简体   繁体   中英

How to prepare request in POST method in Android where two parameters are only Strings where another is JSON object?

Here session_key and user_id are strings. While ' search_data' is json.

I have used the namevalue pairs and json object. But while im combining below request, it is not working together.

I want to create request for below Request :

session_key=71589h9f0ad7a830078a16706569fdee&search_data={"FavoritesUserID":"137","count":6,"start_index":-1,"subcat_id":["12","33","34","35","36","37","38","39","40","62","63"]}&user_id=137

While i am executing above request , i am getting below error all time:

Missing Parameters IN request.

can any one please help me out with proper request where first 2 parameters are only string while other is JSON Object object.

Thanks

The simplest solution will be to choose one type of parameters.

Either wrap all you parameters data as a json:

{
   "height":26,
   "age":21,
   "data":
   {
     "ID":2173.
     ....
   }
}

or treat all your parameters as strings by simply giving the json data a parameter name:

nameValuePairs.add(new BasicNameValuePair("data", createRequest.toString()));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM