[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]);

[NSURL URLWithString:] 返回nil

时间: 2024-08-01 03:09:56

[NSURL URLWithString:] 返回nil的相关文章

iOS URLWithString返回为空nil的解决方案

[NSURL URLWithString:@"----"] 但是貌似汉字或者空格等无法被识别,String不被认为是URLString,这个NSURL的值也就一直是nil 要怎样才能够让它识别呢? 解决方法如下: 1.转换编码 str1 = [str1 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSURL *url = [NSURL URLWithString:[Tool returnFormatS

解决 pathForResource 返回 nil的问题

点击(此处)折叠或打开 NSString* path = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"xml"]; NSLog(@"path=%@",path); NSError *error=nil; NSString* fileText = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncod

解决NSData转NSString返回nil的问题

在使用initWithData等方法将NSData转换成NSString时,如果NSData的内容含有非encoding编码的字符,将会返回nil. ----------SDK文档如下------------- - (instancetype)initWithData:(NSData *)data encoding:(NSStringEncoding)encoding; Return Value An NSString object initialized by converting the b

Xcode bug: imageNamed:方法返回nil

imageNamed:方法返回nil往往有以下几种情况: 项目不存在该图片: 图片命名不正确: 图片的后缀名有问题(往往使用.png的图片,使用.jpg后缀的图片可能会出问题): 设备使用的是Retina屏幕,但是项目没有提供相应的@2x图片: 排除了以上几种常见情况,我的imageNamed:方法仍然返回nil. 最后,把应用从simulator中卸载,退出simulator,关闭并重新启动Xcode,clean项目,重新编译,运行!悲剧的还是不行. 难道是编辑器出问题了?于是,我把代码注释了

【原创】大叔问题定位分享(36)openresty(nginx+lua)中获取不到post数据,ngx.req.get_body_data返回nil

openresty(nginx+lua)中获取不到post数据,ngx.req.get_body_data返回nil This function returns nil if the request body has not been read, the request body has been read into disk temporary files, or the request body has zero size. 打开nginx调试日志 error_log /var/log/ng

解决pathForResource返回nil, 无法读取plist文件问题

有很多人在设置plist文件的时候, 会发现读取不了plist文件里面的内容, 返回值为nil, 下面我们来解决一下这个问题. 首先我们打开工程并且按照下面的步骤来设置: 设置好后, 我们来写一段代码测试一下看看是否添加好: NSBundle *bundle = [NSBundle mainBundle]; NSString *path = [bundle pathForResource:@"images" ofType:@"plist"]; _imageData 

UITableView调用headerViewForSection返回nil问题

本文转载自http://blog.csdn.net/reylen/article/details/47043571,顺便加了一些笔记 在通过 -tableView: viewForHeaderAtSection: 设置headerView,然后再去通过headerViewForSection取的时候 ,发现返回结果为nil: 究其原因 For a Header/Footer, we will take UITableViewHeaderFooterView and use the dequeue

为什么有时候NSData转换成NSString的时候返回nil

有时候,NSData明明有值,可是,当转换成NSString的时候,却没有值,现在来进行测试:) -现在提供测试用素材- 源码如下: // // AppDelegate.m // TestNSData // // Created by YouXianMing on 14-8-30. // Copyright (c) 2014年 YouXianMing. All rights reserved. // #import "AppDelegate.h" @implementation App

iOS6和iOS7环境下微信登录未显示问题&微信IOS的SDK:isWXAppInstalled总是返回NO和nil

一.问题描述: iOS6和iOS7 环境下未显示微信登录界面,在其他环境下显示正常. 二.问题解决: iOS6和7未出现微信登录按钮, 原因 [WXApi isWXAppInstalled] 返回nil和NO: if ([WXApi isWXAppInstalled]) { ... } 修改为如下判断URL: if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"weixin://"]]) {