Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

chrono1081

macrumors G3
Original poster
Jan 26, 2008
8,811
5,741
Isla Nublar
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.
 
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
 
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

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.
 
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).

POST or GET, depends on the web service. Try both, but it should be in the web service documentation.
 
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?
 
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?

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.
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.