• 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: "So I want to connect to the internet in 2008..." / SUMMARY
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "So I want to connect to the internet in 2008..." / SUMMARY


  • Subject: Re: "So I want to connect to the internet in 2008..." / SUMMARY
  • From: JP May <email@hidden>
  • Date: Tue, 24 Jun 2008 11:02:25 +0100

Dear Jens,

To be clear, one has to "roll-your-own" content-length.
No. NSURLRequest will set the Content-Length header for you.
Understood, very good.

Indeed, one would of have to roll-your-own body, i.e., appropriately encoding and adding together your form elements.
Correct.
Right.

There is no built-in support for the standard form encoding format. This is probably because Cocoa is rarely if ever used to implement server-side CGIs; and these days, most client-side programmatic access to web services is done using interfaces like REST or XML-RPC that don't require the client to pretend to be an HTML form.

Yes, that is an EXCELLENT point, I think you're precisely correct.

That said, it's really easy to generate the right output. Looks like you already know the format. To do the correct encoding of the string contents you'll need to call [paramString stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding].

Thanks, that is a great tip.

* ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** *
* ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** *

So in short:


(1) To fetch a simple web page in 2008, you would in fact probably use the Cocoa URL Loading System, NSURL: ie:


http://developer.apple.com/documentation/Cocoa/Conceptual/URLLoadingSystem/Tasks/UsingNSURLConnection.html#//apple_ref/doc/uid/20001836



(2) if you did want to "simulate" a form post, you would use the Mike Cohen Formulation:

- Use a NSMutableURLRequest
- change the method to POST using setHTTPMethod
- add the form content with setHTTPBody
- and finally send the request using a NSURLConnection.

Using the convenient Jens Alfke Tips:

(i) URLRequest will take care of setting the content length for you (no need to calculate it manually), and

(ii) [paramString stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding] is useful for trivially constructing form-like strings.

(if you're unfamiliar with form requests, look at any HTTP doco such as say
http://kobesearch.cpan.org/htdocs/libwww-perl/HTTP/Request/Common.html )





(3) Bearing in mind the Alfke Principle that html-form -like communication is a bit out these days anyway, and something like REST or XML may be more automatically handled more broadly on more environments.




Well this is great.

Thanks to everyone !!!!!!!!!!!!!!!!!!!!!!!!!   J.P. May



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


References: 
 >"So I want to connect to the internet in 2008..." (From: JP May <email@hidden>)
 >Re: "So I want to connect to the internet in 2008..." (From: JP May <email@hidden>)
 >Re: "So I want to connect to the internet in 2008..." (From: Mike Cohen <email@hidden>)
 >Re: "So I want to connect to the internet in 2008..." (From: JP May <email@hidden>)
 >Re: "So I want to connect to the internet in 2008..." (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: "So I want to connect to the internet in 2008..."
  • Next by Date: Re: "So I want to connect to the internet in 2008..."
  • Previous by thread: Re: "So I want to connect to the internet in 2008..."
  • Next by thread: Re: "So I want to connect to the internet in 2008..."
  • Index(es):
    • Date
    • Thread