1

I'm trying to build a small utility for OS X (a statusbar app) using swift that will list all our current clients and when a client is clicked - open up safari with a client url as well as sending a post request (such as login details for a clients WordPress, intranet or other webb application).

NSWorkspace.sharedWorkspace().openURL(NSURL(string: "url")!)

doesn't seem to have a way of incorporating POST data.

It's not for App Store submission, but only internal use within the team.

Any ideas or solutions?

  • you can do it if you open the url in a UIWebView http://stackoverflow.com/questions/32482442/swift-webview-xcode-post-data – SoliQuiD Apr 12 '16 at 21:35
  • another example here http://stackoverflow.com/questions/32834393/post-with-swift-2-on-uiwebview-does-not-work – SoliQuiD Apr 12 '16 at 21:48

1 Answers1

1

You can't achieve that by simply opening an URL - this will always result in a get request, just like typing an URL into the URL bar. "javascript:" URLs cannot be opened via openURL, so this doesn't help either. The best option probably would be to use Apple Script to open the site in a new window and then execute some Java Script to POST the login form.

Sven
  • 22,475
  • 4
  • 52
  • 71
  • Thanks, I was hoping you could in some way create a POST using NSURLRequest or similar that could "post to" Safari. I solved it - extremely ugly - by writing my own php-script accept a GET and output a html form that automatically gets submitted via JS. But it's a horrible solution :) – user3432098 Jun 14 '15 at 18:40
  • @user3432098 can you share approach or code, need same thing – Abhishek Maurya Aug 27 '20 at 06:23