dcsimg
question regarding http post
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   srinivasyadav_maharaj
Posted On:   Sunday, April 29, 2001 07:47 AM

I am doing a http post to a url where i append user email address and some other values. Now, is it required to use URLEncode to encode the values?? or can I just create a string with all the values and write it to stream...does it make any difference... the reason is that URLEncode adds % and other characters for & = and other characters so people who receive it should probably decode the url string. for ex: String url= "http://www.yahoo.com&EMAIL=sri_dynamo@yahoo.com&LIFE[]=howareu&howareu=good&ZIP=08817"; DataOutputStream printout = new DataOutputStream (connection.getOutputStream ()); printout.writeBytes (url); thanks    More>>

I am doing a http post to a url where i append user email address and some other values. Now, is it required to use URLEncode to encode the values?? or can I just create a string with all the values and write it to stream...does it make any difference...
the reason is that URLEncode adds % and other characters for & = and other characters so people who receive it should probably decode the url string.

for ex:
String url= "http://www.yahoo.com&EMAIL=sri_dynamo@yahoo.com&LIFE[]=howareu&howareu=good&ZIP=08817";
DataOutputStream printout = new DataOutputStream (connection.getOutputStream ());
printout.writeBytes (url);


thanks

   <<Less

Re: question regarding http post

Posted By:   AlessandroA_Garbagnati  
Posted On:   Sunday, April 29, 2001 08:53 PM

Hi,

Yes all values that are passed either using GET and POST have to be URLEncoded, to assure that only the right chars are used.

What is happening to you is that you are building the string and then encoding all that string. What, instead, you should do, it's url encoding each value (and even the key if you have special character in it) before building the final string. Something like:

String s += "&" + URLEncoder.encode(key) + "=" + URLEncoder.encode(value);



(ps: if you have to build the string, StringBuffer it's a better choice).
About | Sitemap | Contact