我正在製作一個lo-gin應用程序我想發送用戶名和密碼到服務器進行驗證如何做到這一點我已經在很多方面做了,但我是無法發佈。 我張貼的用戶名和密碼,但如果我直接給用戶名和密碼到PHP它的工作原理,以便如何做到這一點的iphone通過郵局發送如何發送用戶名和密碼使用發佈到iphone服務器中的服務器
NSString *post = [[NSString alloc] initWithFormat:@"UserName=%@&Password=%@",username,pass];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSURL *url = [NSURL URLWithString:@"http://www.celeritas-solutions.com/emrapp/connect.php?"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
[theRequest setHTTPMethod:@"POST"];
theRequest setValue:postLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPBody:postData];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if(theConnection)
{
webData = [[NSMutableData data] retain];
}
else
{
NSLog(@"Inside the else condition");
}
[nameInput resignFirstResponder];
[passInput resignFirstResponder];
nameInput.text = nil;
passInput.text = nil;
看一看[本S.O文章] [1]介紹瞭如何使一個POST請求。 [1]:http://stackoverflow.com/questions/3968107/http-post-request – sergio 2012-03-19 09:34:26
我已經看過這個相同的結果 – user1263350 2012-03-19 09:39:24
添加以下代碼後 – Rupesh 2012-03-19 09:54:50