Can someone give me some clarification regarding web service credentials?

Discussion in 'iOS Programming' started by chrono1081, Jan 7, 2015.

  1. chrono1081 macrumors 604

    chrono1081

    Joined:
    Jan 26, 2008
    Location:
    Isla Nublar
    #1
    Hi guys,

    I've never had to deal with web services before but I have to connect to one that takes three parameters as credentials and passes JSON data. It never downloads (it only receives a cookie) but the app has to upload to it and I'm not sure where to look in the documentation for setting such a thing up.

    I understand that NSURLCredential can pass credentialWithUser, password, and persistence, but I have to pass one more parameter to connect to my web service and I couldn't find anything that seems to support custom parameters.*

    Can anyone give me any guidance on where to look?

    Basically I'm connecting to a secure web service and need to pass a user name, password, and job type as a login credential, but can only find a method passing a username and password.

    I cannot use any third party libraries or utilities either.

    *I have a working app that connects securely to the Big Nerd Ranch web service, I just need to customize it to my apps needs.
     
  2. bbeagle macrumors 68040

    bbeagle

    Joined:
    Oct 19, 2010
    Location:
    Buffalo, NY
    #2
    It looks like you're not actually giving the web service ANY parameters.

    NSURL should be called, and you should pass the credentials as the BODY of the message you send to the web service.

    i.e. NSURL to http://www.webserviceurl/webservicename
    BODY: <xxxxx><username>a</username><password>b</password><job_title>c</job_title>

    The web service should have a .wsdl describing how to send that information (i.e. how to format the XML)

    NSURLCredential is used for a URL of the form:
    http://username@password:www.webserviceurl/webservicename
     
  3. chrono1081 thread starter macrumors 604

    chrono1081

    Joined:
    Jan 26, 2008
    Location:
    Isla Nublar
    #3
    Thanks so much!

    Now from further documentation reading it looks like I have to do this as a POST correct? (Sorry my code is at work I can't give a precise code example).

    Knowing what the body was for is very useful though thanks so much.
     
  4. bbeagle macrumors 68040

    bbeagle

    Joined:
    Oct 19, 2010
    Location:
    Buffalo, NY
    #4
    POST or GET, depends on the web service. Try both, but it should be in the web service documentation.
     
  5. chrono1081 thread starter macrumors 604

    chrono1081

    Joined:
    Jan 26, 2008
    Location:
    Isla Nublar
    #5
    HA! Don't get me started on that!

    It's basically a useless document. No URL, no description of anything, nothing.
     
  6. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #6
    If it's a POST the parameters go in the body if it's a GET the parameters go in the URL.

    Why can't you use any third party libraries?
     
  7. bbeagle macrumors 68040

    bbeagle

    Joined:
    Oct 19, 2010
    Location:
    Buffalo, NY
    #7
    Technically, a POST was meant to send data to a web service, and a GET was meant to retrieve information from a web service (sending parameters that would allow the get to process).... But the web changed the meaning of GET and POST to mean put parameters in the url or body.... It's anyone's guess how this web service works.
     
  8. lht1999 macrumors newbie

    Joined:
    Jan 13, 2015
    #8
    It's usually a POST when you send user name and password to web service in exchange for a cookie (or token). User name and password should be in message body. In future requests you put the cookie in the request http header, so that the request can be GET, POST or DELETE.
     

Share This Page