How to do an HTTP POST in Cocoa

  • Hi,

    I need to perform an HTTP POST to a url in my Cocoa app.
    What is the basic recipe for this in Cocoa as I can only find
    documentation on non-Cocoa classes for this?

    Thanks
  • On 10 Jun 2006, at 12:37, Graham wrote:

    > I need to perform an HTTP POST to a url in my Cocoa app.
    > What is the basic recipe for this in Cocoa as I can only find
    > documentation on non-Cocoa classes for this?

    This was discussed only yesterday.  From my own post in that thread:

    On 9 Jun 2006, at 17:07, Paul Lynch wrote:
    > Why not just use NSURLConnection?  You need to create a
    > NSURLRequest, set the HTTPMethod to "POST", and supply a HTTPBody
    > with your post values.

    Paul
  • Here is how to POST using Cocoa API's:

      NSString* content = [@"item=" stringByAppendingString:@"Something to
    Post"];

      NSURL* url = [NSURL URLWithString:@"http://www.url.com/pagetopost"];
      NSMutableURLRequest* urlRequest = [[NSMutableURLRequest alloc]
    initWithURL:url];
      [urlRequest setHTTPMethod:@"POST"];
      [urlRequest setHTTPBody:[content dataUsingEncoding:
    NSASCIIStringEncoding]];

    After this point you can do several things, such as perform the post in a
    WebKit window, or read this for managing the response:

    http://www.awprofessional.com/articles/article.asp?p=468381&seqNum=2&am
    p;rl=1


    - Kreeger

    On 6/10/06, Graham <graham...> wrote:
    >
    > Hi,
    >
    > I need to perform an HTTP POST to a url in my Cocoa app.
    > What is the basic recipe for this in Cocoa as I can only find
    > documentation on non-Cocoa classes for this?
    >
    > Thanks
    > _______________________________________________
    > Do not post admin requests to the list. They will be ignored.
    > Cocoa-dev mailing list      (<Cocoa-dev...>)
    > Help/Unsubscribe/Update your Subscription:
    > http://lists.apple.com/mailman/options/cocoa-dev/<kreeger.dev...>
    >
    > This email sent to <kreeger.dev...>
    >