• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSURLConnection substitutes characters?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSURLConnection substitutes characters?


  • Subject: Re: NSURLConnection substitutes characters?
  • From: Stefan Arentz <email@hidden>
  • Date: Sun, 13 Jul 2008 00:37:30 -0400


On Jul 13, 2008, at 12:25 AM, email@hidden wrote:


-------------- Original message ---------------------- From: Stefan Arentz <email@hidden>

If you want to send Base64 encoded data in a query parameter (or post
data) then you will need to 'percentage-escape' it properly. In which
case a '+' needs to be translated to a '+'.


I posted basically the same question on a PHP forum and one poster set off a lightbulb. I use the following method in the PHPInvocation class to build the post and because of my choice of "Content-Type" in the httpHeaderField of the NSMutableURLRequest, the data is getting urlencoded on the Cocoa end.


+ (id) phpRequestWithURL:(NSURL *) inURL
data:(NSData *) inData
{
NSMutableURLRequest *result = [NSMutableURLRequest requestWithURL: inURL];
NSString *dataLength = [[NSNumber numberWithInt: [inData length]] stringValue];

[result setHTTPMethod: @"POST"];
[result setValue: @"application/x-www-form-urlencoded" forHTTPHeaderField: @"Content-type"];
[result setValue: dataLength forHTTPHeaderField: @"Content-length"];
[result setValue: @"close" forHTTPHeaderField: @"Connection"];
[result setHTTPBody: inData];

return result;
}


Is there some content type I could use other than "application/x-www- form-urlencoded" that would work with PHP scripts?

Depends on what you are posting to the script :-)

If it is a query string then the above is correct. If it is XML or JSON then you probably want to use something different.

 S.

_______________________________________________

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


References: 
 >Re: NSURLConnection substitutes characters? (From: email@hidden)

  • Prev by Date: Re: Trigonometric Problem, Particularly tan() Function
  • Next by Date: Re: Trigonometric Problem, Particularly tan() Function
  • Previous by thread: Re: NSURLConnection substitutes characters?
  • Next by thread: Re: NSURLConnection substitutes characters?
  • Index(es):
    • Date
    • Thread