[NSURL URLWithString:] 返回nil
2014-08-14 16:17
706 查看
具体问题原因是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]);
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]);
相关文章推荐
- [nsurl urlwithString:] 返回结果为nil
- stringWithContentsOfURL:encoding:error方法返回nil
- 直接用URLWithString来拼接NSURL有时候得到的NSURL是为nil的
- [iOS常见问题] 本地文件路径[NSURL URLWithString:] 获得的值为空nil
- iOS URLWithString返回为空nil的解决方案
- NSURL URLWithString return nil 问题解决
- 直接用URLWithString来拼接NSURL有时候得到的NSURL是为nil的
- [IOS] URLWithString拼接NSURL时,url=nil的问题
- NSURL使用urlWithString得到的对象为nil的问题原因以及解决
- 直接用URLWithString来拼接NSURL有时候得到的NSURL是为nil的
- 直接用URLWithString来拼接NSURL有时候得到的NSURL是为nil的
- reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter' 产生崩溃
- URLWithString:初始化为nil的问题
- iOS --- 使用NSURL的urlWithString时,尽量先对字符串进行UTF8转码
- iphone:URL initWithString 返回为空
- IOS--错误集锦--reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'
- [NSURL initFileURLWithPath:]: nil string parameter 错误的解决方案
- [NSURL URLWithString:] returns nil
- IOS--错误集锦--reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'
- 【NSURL URLWithString:url 】中string不为空而URL输出为空的情况