How to send a String array as basic name value pair as HTTPPOST?

后端 未结 4 959
夕颜
夕颜 2020-12-03 07:52

I want to send a array as name value pair as httppost.My server accepts only array values.The following is my code snippet..

public String SearchWithType(Str         


        
相关标签:
4条回答
  • 2020-12-03 08:32

    json_array = [{param1:"param1Value", param2:"param2Value"}] if you want send a json array with nameValuePairs you can send like this;

    new BasicNameValuePairs("param[0][param1]","param1Value")
    new BasicNameValuePairs("param[0][param2]","param2Value")
    
    0 讨论(0)
  • 2020-12-03 08:36
    nameValuePairs.add(new BasicNameValuePair("type", Arrays.toString(type)));
    
    0 讨论(0)
  • 2020-12-03 08:37

    I got the issue. Here's how:

    try {
        int i = 0;
    
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        nameValuePairs.add(new BasicNameValuePair("authentication_token", auth_token));
        nameValuePairs.add(new BasicNameValuePair("key", key));
        nameValuePairs.add(new BasicNameValuePair("category_name", category_name));
        nameValuePairs.add(new BasicNameValuePair("type", type[i]));
        nameValuePairs.add(new BasicNameValuePair("page", String.valueOf(page_no)));
    
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
    
        eu = EntityUtils.toString(entity).toString();
    } catch (Exception e) {
        Log.e(TAG, e.toString());
    }
    

    All I had to do was initialize a loop:

    for (int i = 0; i < type.length; i++) {
        nameValuePairs.add(new BasicNameValuePair("type[]",type[i]));
    }
    
    0 讨论(0)
  • 2020-12-03 08:39

    convert from array to string and then send using http post,again server side parse from String to array

    0 讨论(0)
提交回复
热议问题