Ahmad Arslan
Ahmad Arslan

Reputation: 4528

Remove or replace special character in namevaluepair for http post request android

I have a problem when I tried to post my data it logged as :

[ObserverTRID=5QEET3TE10,
 ObsType=Evaluate,
 ObsDate=17-Jul-2014, 
ObsTime=09:22:12, 
// == loc

ObsTitle=bolllloooo, 

//==obstset
MediaData={"MediaData":[{"RunNo":0,"Filename":"http://url/5QEET3TE10_3_5_20140717092206.jpg","MediaNo":4"Desc":01 Image_17-Jul-14No Marker.jpg}]}, 
PVPMediaCount=1, 
SourceDevice=motorola XT1032 Android v19 App v2.0001,
 ObsDept,
 ObsSite, 
TargetTRID=5QEET3TE10]

But I need to append every namevalue with "&" instead of "," This is my httppost request.

httppost.setEntity(new UrlEncodedFormEntity(mNameValuePairs));

This is my request i am posting the URL with the parameter nameevaluepair

DefaultHttpClient httpclient = new DefaultHttpClient();

    HttpPost httppost = new HttpPost(mUrl);


            if(mNameValuePairs==null){
                mNameValuePairs = new ArrayList<NameValuePair>(1);
                mNameValuePairs.add(new BasicNameValuePair("PostEvent", "Null"));
            }
            Log.e("namevalue ", mNameValuePairs.toString());

There I am settig entity by URLEncoding

        httppost.setEntity(new UrlEncodedFormEntity(mNameValuePairs));
        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httppost);
        String result = EntityUtils.toString(response.getEntity(),HTTP.UTF_8);



        HttpEntity httpEntity = response.getEntity();

Upvotes: 0

Views: 1000

Answers (1)

Surya Prakash Kushawah
Surya Prakash Kushawah

Reputation: 3201

            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(url);
            httpPost.setEntity(new UrlEncodedFormEntity(params));

            HttpResponse httpResponse = httpClient.execute(httpPost);
            HttpEntity httpEntity = httpResponse.getEntity();

use this code in for parsing class

Upvotes: 0

Related Questions