Saturday 15 February 2014

android - NameValuePair how to send blanks -


I need to send some values ​​for a service via HTTP post. I will be empty in one of the parameters to be sent The place should be the "key" NVP but the service always retrieves an unsuccessful message, as soon as I add the value, which works.

Now this is the catch, when a request is made for the same service through the iPhone device, then it works just fine when they send blank, am I missing something in my request Can I send empty values ​​to nameVauePair?

This is my navewhipier

  list & lt; NameValuePair & gt; NameValuePairs = New ArrayList & lt; NameValuePair & gt; (5); NameValuePairs.add (New BasicNameValuePair ("id", "1")); NameValuePairs.add (New BasicNameValuePair ("uId", android_id)); NameValuePairs.add (new BasicNameValuePair ("key", "")); // This value should be an empty name ValuePairs.add (New BasicNameValuePair ("rate", "0")); NameValuePairs.add (New BasicNameValuePair ("Notes", Notes));   

This is my first request

  http client httpclient = new DefaultHttpClient (); HttpPost httppost = New HttpPost (context.getResources () .getString (R.string.url_event_rating)); Try {httppost.setEntity (new UrlEncodedFormEntity (nameValuePairs, "utf-8")); // Execute HTTP Post Request HTTP Response Response = httpclient.execute (httppost); String ReactionBody = EntityUtils.toString (Response .getEntity ()); } Hold (ClientProtocolException E) {Log D. ("Client Protocol Exposure", E. Message ()); } Hold (IOException e) {log d. ("IOE Expansion", EZT Message ()); }    

adding SP instead of a literal space character Try. This is the syntax given by BasicNameValuePair: (specifies the general overview of the class) and (specifies the token accepts).

Basically, you want to insert SP instead ", what I have read on this topic.

Edit: According to the second link above: SP = & lt; US-ASCII Sp, Space (32) & gt; Essentially, either a character whose value is 32 (decimal) or 0x20 (hex). Or change your encoding to UrlEncodedFormEntity (nameValuePairs, "utf-8") to "US-ASCII" .

No comments:

Post a Comment