Comments (6)
I added the URL to the HTTPResponse. So for example:
var request = HTTPTask()
//we have to add the explicit type, else the wrong type is inferred. See the vluxe.io article for more info.
let params: Dictionary<String,AnyObject> = ["param": "param1", "array": ["first array element","second","third"], "num": 23, "dict": ["someKey": "someVal"]]
request.POST("http://domain.com/create", parameters: params, success: {(response: HTTPResponse) in
println(response.URL) // URL of response.
},failure: {(error: NSError, response: HTTPResponse?) in
})
Just pull the latest code and you should be golden.
from swifthttp.
Thanks for your response. What happens when there is a HTTP redirect?
from swifthttp.
Since it is just a wrapper around NSURLSessionDataTask
according to Apple's Docs:
"If the delegate does not implement this method, the redirect is followed up to the maximum number of redirects."
We don't implement the delegate method, so it should just follow them by default. Check out the Apple docs for more info.
from swifthttp.
Excuse me if I'm asking too many question! Does NSURLSessionDataTask
maintain cookies too? I'm asking because I want to do an "OAuth in memory". The login page has some cookies that is needed for POST operation when user clicks on login button. So I want to GET the login page, and then in the same session, POST to endpoint that login page form POST to with cookies.
Here is the flow I want to follow:
- GET login page at
/
- After login loaded, POST to
/login
with cookies and username/password I got from user from previous GET request - After successful login, wait for redirects to resolve and then capture OAuth token from the URL.
from swifthttp.
Not at all. Questions are good 😄. SwiftHTTP is a pretty thin wrapper around NSURLSession, so I was just wanting to point you to source for docs from Apple. Cookies are in the same boat as redirects. We don't handle them directly and use just use the builtinNSHTTPCookieStorage
for NSURLSession
. According to the docs:
For default and background sessions, the default value is the shared cookie storage object.
For ephemeral sessions, the default value is a private cookie storage object that stores data in memory only, and is destroyed when you invalidate the session.
So by default cookies are per NSURLSession, or in more general terms stored per request. Not sure if this would help any, but I have a simple example Github app that implements Github's OAuth using SwiftHTTP. It doesn't use the "web flow", but might be helpful all the same.
https://github.com/acmacalister/Github-Swift
from swifthttp.
Thank you very much! I'll try this.
from swifthttp.
Related Issues (20)
- Count is unavailable: there is no universally good answer, see the documentation comment for discussion HOT 5
- HTTP.POST() not working after screen-lock (iOS 9.3.5)
- How to handler download progress?
- 'count' is unavailable: there is no universally good answer, see the documentation comment for discussion
- failed in xcode9.3
- Pinning Trusted certs or keys HOT 2
- POST method parameters lost in traffic
- Parameters not converted properly when using arrays HOT 2
- Cannot upload file
- Progress closure seems broken
- Post objects array to server
- Ambiguous use of 'init(urlString:parameters:headers:cachePolicy:timeoutInterval:)'
- Retry a task?
- Why OperationQueue support has been removed?
- SSL Pinning - Code=-999 "cancelled" HOT 1
- Linux support ?
- Timeout
- 'taskMap' Dictionary related crashes in Operation.swift file HOT 3
- Cannot consume as Swift package
- SSL Pinning - Always failing
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swifthttp.