发送http请求返回<>

时间:2012-11-11 07:43:43

标签: ios

我试图通过登录表单来检查用户名&使用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);
}

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

1 个答案:

答案 0 :(得分:1)

NSString *post = @"rawStrusername&rawStrpassword";

您是要将“rawStrusername&rawStrpassword”字符串发送到服务器吗?你为什么不尝试:

NSString *post = [NSString stringWithFormat:@"%@&%@", rawStrusername, rawStrpassword];