I want to post a string array and a object to server using Loop j

46 Views Asked by At

Every time I get the error "BAD Request". I'm trying to post data like this json

{
"name":"testOne",
"location": "['one','two','three']"
}

Here is my Code

    AsyncHttpClient client = new AsyncHttpClient();
    String someData="{\"name\":\"testOne\",\"location\": \"['ne','two','three']\"}";
    ByteArrayEntity be = new ByteArrayEntity(someData.toString().getBytes());
    client.post(MainActivity.this, "http://impero-dannyfast.rhcloud.com/api/agents", be, "application/json", new AsyncHttpResponseHandler() {
        @Override
        public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {

            Toast.makeText(MainActivity.this, "Succ", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {

            Toast.makeText(MainActivity.this, "fail"+statusCode, Toast.LENGTH_SHORT).show();

        }

        });
2

There are 2 best solutions below

0
On
{
"name":"testOne",
"location": ["one","two","three"]
}

try sending like this

2
On