-4
{"value":"CUSTOM","allow":"ALL_FRIENDS","deny":"100000415571929,1340463778"}

I need to send this to this data as a http request,I am getting Illegal character errors.

How to send these special characters?

Thanks

Ben Carey
  • 16,540
  • 19
  • 87
  • 169
user1891910
  • 919
  • 3
  • 18
  • 45

2 Answers2

2

Try the URLEncoder class, it should work

String url = "http://example.com/query?q=" + URLEncoder.encode("{\"value\":\"CUSTOM\",\"allow\":\"ALL_FRIENDS\",\"deny\":\"100000415571929,1340463778\"}", "ISO-8859-1");

Hope I didn't miss any scape character :P

Mathias Schwarz
  • 7,099
  • 23
  • 28
Adrián Rodríguez
  • 1,836
  • 15
  • 16
0

Try in this way :

HttpPost post = new HttpPost(postURL);

List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("value","CUSTOM"));
params.add(new BasicNameValuePair("allow","ALL_FRIENDS"));
params.add(new BasicNameValuePair("deny","100000415571929,1340463778"));

UrlEncodedFormEntity ent = new UrlEncodedFormEntity(params,HTTP.UTF_8);
post.setEntity(ent);

Hope it helps you.

Thanks.

Pratik Sharma
  • 13,307
  • 5
  • 27
  • 37