views:

71

answers:

1

Hello stackoverflow,

Have a slight problem. Trying to post XML to a server. To do this, I have to encode the XML string in URL format.

NSString *encodedString = [NSString stringWithFormat:@"xmlValue=%@",[post stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding]];

That's what I have and it works for all the characters EXCEPT the '='. This does not get converted to %3D. Has anyone else ever had this problem before? Am I specifying the wrong encoding type? I have tried "NSUTF8StringEncoding" as well.

This is a little piece of the XML string:

@"<xml-service application=\"broadcast\" type=\"REQUEST\"><identity token=\"xxxxxxxx\".....

Any help would be appreciated! Thanks

+2  A: 

Check this out:

http://simonwoodside.com/weblog/2009/4/22/how_to_really_url_encode/

Ben
Ok I saw that, how do I convert that to data once I encode it? The only thing I can find is: NSData *postData = [encodedString dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES]; Does that ruin the encoding when I go to post it?
Geoff Baum
It should work ok since the string is already encoded. I don't think you necessarily need the allowLossyConversion part though.
Ben
Ok it must be another problem then. The server is claiming that I am sending invalid XML for some reason.
Geoff Baum
But I do suppose that was the solution for my initial problem :) The string was successfully encoded. Thanks!
Geoff Baum