Re: NSPropertyListSerialization and string encoding
Re: NSPropertyListSerialization and string encoding
- Subject: Re: NSPropertyListSerialization and string encoding
- From: Kyle Sluder <email@hidden>
- Date: Fri, 23 Jul 2010 09:50:07 -0700
On Fri, Jul 23, 2010 at 9:34 AM, Joe Turner <email@hidden> wrote:
> Hey,
>
> No one is requiring me to send a string–I do indeed send it as data, but I must convert values from string to data. Like, I have a title field, in which I must convert the title to NSData. But since there are a bunch of arguments like this, I just make a string like @"arg1=something&arg2=something...", and then do [dataUsingEncoding:allowLossyConversion:.
>
> Should I be doing this a better way? (I'm the one who created the web service, so if there's an issue with doing it this way, I can easily change it).
Yes. The better way is not to use NSString, since strings are a
conceptually different beast from data. You might start out with a
string (say, the user types something into a text field), but you want
to convert that to data at some point before tacking it on to the rest
of the data that comprises your POST request. Don't conflate the two,
which you're doing by trying to build a string that contains your
urlencoded POST data. Convert the strings to data *first*, then
compile all your data into a POST request.
--Kyle Sluder
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden