Skip to content Skip to sidebar Skip to footer

Passing Array Of Objects As Url Parameters In Request

I need to put an array of objects ( each object has 2 fields ) as parameters in url of http request. How can i do it and how should this link looks like?

Solution 1:

You can make an xml with your structure i.e an array of objects each having two fields then convert that to string as, As an example,

       String  input = String.format("<Request><Data><Id>%s</Id></Data></Request>",studentIdSelected);

Then call this method with input and url as parameters for posting your data,

publicstatic String retriver(String Url, String input) {

    StringresponseString=null;
    StringEntity stringEntity;
    HttpPostpostRequest=newHttpPost(Url);
    try {

        Log.e("string is", input + "\n" + Url);
        stringEntity = newStringEntity(input, "UTF-8");
        stringEntity.setContentType("application/atom+xml");

        postRequest.setEntity(stringEntity);
        Log.v("Post", "Posted");
        HttpClienthttpclient=newDefaultHttpClient();
        HttpResponseresponse= httpclient.execute(postRequest);  
        HttpEntitygetResponseEntity= response.getEntity();

        responseString = EntityUtils.toString(getResponseEntity);

    } catch (Exception e) {
        // TODO: handle exception
        postRequest.abort();
        Log.w("HttpPostRetreiver", "Error for URL " + Url, e);
    }

    return responseString;

}

Alternatively you can use json as well.

Solution 2:

best solution is send http post request in json or xml format .

Post a Comment for "Passing Array Of Objects As Url Parameters In Request"