-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
  • 15,748
  • 19
  • 82
  • 158
user1891910
  • 891
  • 2
  • 18
  • 44

2 Answers2

3

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
  • 6,939
  • 21
  • 28
Adrián Rodríguez
  • 1,851
  • 14
  • 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,119
  • 5
  • 25
  • 36