0

我试图制作登录表单以使用 http 请求从外部服务器检查用户名和密码,但给出了响应 <>

- (IBAction)getlogin:(UIButton *)sender {
    NSString *rawStrusername = [NSString stringWithFormat:@"username=%@",_username.text];
    NSString *rawStrpassword = [NSString stringWithFormat:@"password=%@",_password.text];

    NSString *post = @"rawStrusername&rawStrpassword";
    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
   /*
    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];*/
    NSURL *url = [NSURL URLWithString:@"http://www.othaimmarkets.com/my_services_path/user/login"];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: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 *err;
    NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
    NSLog(@"responseData: %@", responseData);
}

任何帮助、建议或示例将不胜感激

4

1 回答 1

1
NSString *post = @"rawStrusername&rawStrpassword";

You are sending the "rawStrusername&rawStrpassword" string to the server? Why don't you try with:

NSString *post = [NSString stringWithFormat:@"%@&%@", rawStrusername, rawStrpassword];
于 2012-11-11T09:40:46.130 回答