首页 > 代码库 > [NSURL URLWithString:] 返回nil

[NSURL URLWithString:] 返回nil

具体问题原因是url中输入的有中文,那么这个就看作非法的字符无法识别。这种的必须使用post方式来发送消息。具体为:

            tmp = mainurl;
            [parameters appendString:key];
            [parameters appendString:value];

NSURL * downloadUrl = [NSURL URLWithString:self.strURL];
        NSMutableURLRequest *requestL = [NSMutableURLRequest requestWithURL:downloadUrl
                                                                cachePolicy:NSURLRequestReloadIgnoringCacheData
                                                            timeoutInterval:60.0];
        [requestL setHTTPMethod:@"POST"];
        NSString *postString = parameters;
        [requestL setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
        NSLog(@"the post body is %@",[NSString stringWithFormat:@"%@", postString]);