您好我正在尝试连接到将使用用户名和密码作为凭据的某些服务器。以下是我正在使用的代码。NSString post =[[NSString alloc] initWithFormat:@"userName=*&password=* "]; NSURL url=[NSURL URLWithString:@"** * *** "];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[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];
NSLog(@"request:%@",request);
urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
这里的问题是服务器给用户无效的消息。但我给的凭据很好。这个用户名和密码没有进入请求对象..你们中的任何一个都可以帮助我..