Coder Social home page Coder Social logo

How do I get response URL? about swifthttp HOT 6 CLOSED

mohsen1 avatar mohsen1 commented on August 27, 2024
How do I get response URL?

from swifthttp.

Comments (6)

acmacalister avatar acmacalister commented on August 27, 2024

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.

mohsen1 avatar mohsen1 commented on August 27, 2024

Thanks for your response. What happens when there is a HTTP redirect?

from swifthttp.

acmacalister avatar acmacalister commented on August 27, 2024

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.

https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/URLLoadingSystem/NSURLSessionConcepts/NSURLSessionConcepts.html

from swifthttp.

mohsen1 avatar mohsen1 commented on August 27, 2024

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:

  1. GET login page at /
  2. After login loaded, POST to /login with cookies and username/password I got from user from previous GET request
  3. After successful login, wait for redirects to resolve and then capture OAuth token from the URL.

from swifthttp.

acmacalister avatar acmacalister commented on August 27, 2024

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

https://developer.apple.com/library/ios/Documentation/Foundation/Reference/NSURLSessionConfiguration_class/index.html#//apple_ref/doc/uid/TP40013440-CH1-SW12

from swifthttp.

mohsen1 avatar mohsen1 commented on August 27, 2024

Thank you very much! I'll try this.

from swifthttp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.