So I’m looking to move an app away from using do shell script for curl operations.
I’m hitting something that seems odd, wherein when I create a URL with NSURL’s URLWithString, what I’m getting back is the result of the URL on the website, not a URL object?
This isn’t bad in and of itself for GET operations, but if it’s a URL for a post, where there’s nothing returned when "running’ the URL, then I get missing value.
Of the two, NSURLConnection is deprecated, but I suspect it will be supported for a while. And it’s easier to use from AppleScript, partly because it has a synchronous option. Simpler stuff can be done like this:
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
set theNSURL to current application's |NSURL|'s URLWithString:theString
set theNSURLRequest to current application's NSURLRequest's alloc()'s initWithURL:theNSURL cachePolicy:(current application's NSURLRequestReloadIgnoringCacheData) timeoutInterval:5.0
set {theNSURLConnection, theResponse, theError} to current application's NSURLConnection's sendSynchronousRequest:theNSURLRequest returningResponse:(reference) |error|:(reference)
Okay, so next question, how do you set the HTTP Method (get/post) etc. I’ve tried a few options, none of them seem to be working. (lots of unrecogonized selectors)