1

This is the structure of parameters i want to send through httpPost and BasicNameValuePair. is there any way that i could do this. or if there is any other method please let me know. [In Android App]

{

page    : 0

 retailer: [

0:{
    id = "72"
    type = [ 1,2 ]
      }

1:{
    id = "76"
    type = [ 2,4 ]
      }

      ]

  message_type    : null

 }
riskPlayGround
  • 122
  • 2
  • 12

2 Answers2

0

use the below code to pass data as NameValue pair in android

      public void postData() {
        // Create a new HttpClient and Post Header
   HttpClient httpclient = new DefaultHttpClient();
 HttpPost httppost = new HttpPost("http://www.yoursite.com/script.php");

  try {
   // Add your data
      //you can add all the parameters your php needs in the BasicNameValuePair. 
       //The first parameter refers to the name in the php field for example
         // $id=$_POST['customerId']; the second parameter is the value.
          List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
     nameValuePairs.add(new BasicNameValuePair("id ", "72"));
        nameValuePairs.add(new BasicNameValuePair("type ", "1.2"));

      httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

          // Execute HTTP Post Request
             HttpResponse response = httpclient.execute(httppost);

              } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
              } catch (IOException e) {
         // TODO Auto-generated catch block
        }}
user1835052
  • 465
  • 1
  • 5
  • 11
0

this may helps you

this for passing String array List in namvalues

public List<NameValuePair> namevalueFunction(ArrayList<String> selectedImages) {
        for(int i=0;i<selectedImages.size();i++)
        {
            nvp.add(new BasicNameValuePair("UMI_NAME"+i,selectedImages.get(i)));
        }
        return nvp;
    }

this for passing String in namvalues

public List<NameValuePair> getInviteEmailValuePair(String email) {
        nvp.add(new BasicNameValuePair("invitebyemail",email));

        return nvp;

    }
Ankitkumar Makwana
  • 3,664
  • 3
  • 16
  • 44