0
我已經做了一個PHP Web服務,它從iPhone應用程序獲取用戶名和密碼並將數據保存在用戶表中。無法從iPhone應用程序獲取數據
我調用Web服務從我的按鈕觸上事件是這樣的:
NSLog(userName.text);
NSLog(password.text);
NSString * dataTOB=[userName.text stringByAppendingString:password.text];
NSLog(dataTOB);
NSData * postData=[dataTOB dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSLog(postLength);
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://localhost:8888/write.php"]];
[request setURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLResponse *response;
NSError *error;
[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if(error==nil)
NSLog(@"Error is nil");
else
NSLog(@"Error is not nil");
NSLog(@"success!");
我正在從iPhone側面什麼到Web服務,我無法理解爲什麼這種情況正在發生。雖然我調試,發現一切都在iPhone應用水平,但並沒有按預期工作調用Web服務細......
請建議.....
感謝 Ashish