Coldfusion Calls in Objective-C
So a client right now is asking me to send requests that are synchronous to an example he gave me that is in Coldfusion, and seeing as I have no real experience with Coldfusion I was wondering how I could run the following command(request?) on the iPhone:
<cfhttp method="post开发者_StackOverflow社区" username="6Z3YcQhPTZWcCHG0o9OcFA" url="https://url.com/api/device_tokens/<devicetoken>" password="UL2PJ6UnSS6272afQJM2Jw">
<cfhttpparam name="Content-Type" value="application/json" type="header" />
<cfhttpparam value="{}" type="body" />
Thank you in advance! It is really appreciated!
This should be the equivalent (untested, though):
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://6Z3YcQhPTZWcCHG0o9OcFA:UL2PJ6UnSS6272afQJM2Jw@url.com/api/device_tokens/<devicetoken>"]];
[theRequest addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody:[[NSString stringWithString:@"{}"] dataUsingEncoding:NSASCIIStringEncoding]];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) {
// Create your data object here, then fill your object by responding to the appropriate delegate methods
} else {
// NSError out
}
If you need help beyond that, you're going to have to read the URL Loading System reference.
There's no Coldfusion runtime for the iPhone.
精彩评论