ios网络请求Content-Type为application/x-www-form-urlencoded

来源:互联网 发布:如何启动mysql 编辑:程序博客网 时间:2024/06/05 01:01

ios网络请求Content-Type为application/x-www-form-urlencoded

by 伍雪颖

NSHTTPURLResponse *response = nil;    NSError *error = nil;    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://115.28.131.98:83/auth"]];    request.HTTPMethod = @"POST";    [request addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];    NSString *postStr = [NSString stringWithFormat:@"useremail=%@&password=%@",_emailTextfield.text,[WTMd5Encoding md5:_passwordTextfield.text]];    [request setHTTPBody:[postStr dataUsingEncoding:NSUTF8StringEncoding]];    NSData *respData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];    NSLog(@"%d-%@", [response statusCode],[NSString stringWithUTF8String:[respData bytes]]);    if ([response statusCode] == 200) {        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{                [self pushToMainPage:nil];            });    }        NSHTTPURLResponse *response = nil;    NSError *error = nil;    NSMutableURLRequest *postRequest = [[AFHTTPRequestSerializer serializer] requestWithMethod:@"POST" URLString:@"http://115.28.131.98:83/auth" parameters:@{@"useremail": _emailTextfield.text,@"password":[WTMd5Encoding md5:_passwordTextfield.text]} error:&error];    NSData *respData = [NSURLConnection sendSynchronousRequest:postRequest returningResponse:&response error:&error];    NSLog(@"%d-%@", [response statusCode],[NSString stringWithUTF8String:[respData bytes]]);    if ([response statusCode] == 200) {        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{            [self pushToMainPage:nil];        });    }


0 0
原创粉丝点击