• 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: Open safari and send post variables
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Open safari and send post variables


  • Subject: Re: Open safari and send post variables
  • From: Ken Tozier <email@hidden>
  • Date: Fri, 9 Jun 2006 13:12:46 -0400

// use the data any way you like

On Jun 9, 2006, at 12:01 PM, Yorh wrote:

Yes true,

But how can I send post variables to my view?
If I use the standard url connection the delegate returns me an NSData object... and I 'm not able to display the page :(


Is there any way to do it?

I communicate with PHP scripts on a server directly by doing the following.


NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: <some php script url here>];
NSData *body = <some data here>;
NSString *bodyLength = [[NSNumber numberWithInt: [body length]] stringValue];
NSHTTPURLResponse *response;
NSError *error;


// generate the HTTP POST
[request setHTTPMethod: @"POST"];
[request setValue: @"application/x-www-form-urlencoded" forHTTPHeaderField: @"Content-type"];
[request setValue: bodyLength forHTTPHeaderField: @"Content-length"];
[request setValue: @"close" forHTTPHeaderField: @"Connection"];
[request setHTTPBody: body];


// send it away
result        = [NSURLConnection sendSynchronousRequest: request
                        returningResponse: &response
                        error: &error];

// process result if any
if ((result != nil) && ([result length] > 0))
{
NSString *temp = [[NSString alloc] initWithBytes: [result bytes]
length: [result length]
encoding: NSUTF8StringEncoding];


    NSLog(@"http reply = %@", temp);
}
else if (error != NULL)
{
    // something went awry log HTTP header and error
    NSLog(@"response = %@", [response allHeaderFields]);
    NSLog(@"error = %@", error);
}


In addition, it's fairly easy to serialize Cocoa dictionaries (although it's too big to post to the list) into php arrays and have php grab the data and us it directly like this:


$data_from_cocoa_app    = unserialize(stripslashes($_POST['query']));


To send it back to you app all you have to do is

echo $result

Serilization helps on this end to convert it to an NSDictionary but it's too big to post.

If you are interested in the serialization code let me know and I'll email it to you off-list

Ken
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Re: Open safari and send post variables (From: Keary Suska <email@hidden>)
 >Re: Open safari and send post variables (From: Ken Tozier <email@hidden>)
 >Re: Open safari and send post variables (From: Yorh <email@hidden>)
 >Re: Open safari and send post variables (From: August Trometer <email@hidden>)
 >Re: Open safari and send post variables (From: Yorh <email@hidden>)

  • Prev by Date: Handling hyperlinks in an NSBrowserCell
  • Next by Date: avoiding drags?
  • Previous by thread: Re: Open safari and send post variables
  • Next by thread: Re: Open safari and send post variables
  • Index(es):
    • Date
    • Thread