views:

67

answers:

1

I'm using the following code to submit to a WCF service. I keep getting an error that the key is invalid. I have a webpage on the same server that I submit the same data (but different key) using a FORM POST. It works fine that way. I put the URL below all in a URL (including valid key from server webpage) and get the key is invalid error. I'm thinking the data I'm submitting through the iPhone isn't really going across as a FORM POST but rather as a URL.

Is there anything I may be doing wrong in the following code or any other suggestions?

    NSString *stringForURL = @"https://abc.com/someservice.aspx";
NSURL *URL=[[NSURL alloc] initWithString:stringForURL];
  NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];

NSString *request_body = [NSString stringWithFormat:@"prop1=value1&key=%@",
                                                    [@"r2xHEuzgDTQEWA5Xe6+k9BSVrgsMX2mWQBW/39nqT4s=" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

NSData *postData = [request_body dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[NSThread sleepForTimeInterval:1];
self.receivedData = [[NSMutableData data] retain];

--- EDIT ---

The above code seems to be submitting everything through a URL rather than FORM POST. When I put the entire string in as a URL, I get the invalid session key error. I created an HTML page with a FORM in it and submitted without HTTPS. That worked fine. When I tried this in the iPhone, I get a message that SSL is required. I go back to the URL without HTTPS and get that same message (SSL is required). Seems I'm missing something to create the FORM POST.

+1  A: 

Please go to the following link, i hope it will help you,

1)kosmaczewski.net 2)http://icodeblog.com/2008/11/03/iphone-programming-tutorial-intro-to-soap-web-services/ 3)http://viium.com

RRB