0

i'm using Ion library for posting data on server database in string name/value pairs and getting JSON response. Say you have a table 'A' in Database with Attributes 'x' and 'y' (say varchars), so you can post a record in table like this :

 Ion.with(getContext())
    .load("https://abc/api/A")
    .setBodyParameter("x", "somevalue")
    .setBodyParameter("y", "anothervalue")
    .asString()

I want to post a number of records to be inserted in table at once, what i'm doing is :

 Ion.with(getContext())
    .load("https://abc/api/A")
    .setBodyParameter("x[0]", "somevalue")
    .setBodyParameter("y[0]", "anothervalue")
    .setBodyParameter("x[1]", "somevalue")
    .setBodyParameter("y[1]", "anothervalue")
    .setBodyParameter("x[2]", "somevalue")
    .setBodyParameter("y[2]", "anothervalue")
    .asString()

if anybody is familiar with ion , please guide me. Here is the link to github project of Ion : https://github.com/koush/ion

Adeel Ahmad
  • 990
  • 8
  • 22
  • Depends on how you want to post. This will post URL encoded values. Maybe your server accepts multipart or JSON. – koush Sep 26 '15 at 17:18

1 Answers1

0

Try this

Ion.with(getContext())
    .load("https://abc/api/A")
    .setBodyParameter("x[]", "a value")
    .setBodyParameter("x[]", "b value")
    .setBodyParameter("x[]", "c value")
    .setBodyParameter("y[]", "d value")
    .setBodyParameter("y[]", "e value")
    .setBodyParameter("y[]", "f value")
    .asString()

Then in your server (eg. PHP)

<?php
$xvalues= $_POST['x'];
$yvalues= $_POST['y'];

$_POST['x'] and $_POST['y'] will return array of values loop it to insert to database.

Sabeer
  • 3,940
  • 1
  • 24
  • 20