NSURL not getting allocatd with NSString

别来无恙 提交于 2019-12-13 03:31:54

问题


This' strange because all my other NSUrls in program are working properly but this one isn't getting allocated with NSString. I'm using:

urlStr_ = [NSString stringWithFormat:@"http://192.168.10.2/justmeans/trunk/appaddgoodwork?gencode=%@&deviceid=@%@&sessionkey=%@&userid=%@&updatetext=%@&companyid=%d&service_type=%@",securitycode,deviceId,sessionKey,userId,finalTextInTxtVw,companyId,service_type];
urlStr_ = [urlStr_ stringByAddingPercentEscapesUsingEncoding:(NSStringEncoding)NSUTF8StringEncoding];

url_ = [[NSURL alloc] initWithString:urlStr_];

What are the possible reasons for NSUrl not getting allocated? Can anybody please help?

Thanx in advance.

P.S. NSString is not empty.


回答1:


The string seems to not be correctly formatted. See the %@&deviceid=@%@&sessionkey part; should not it be %@&deviceid=%@&sessionkey?




回答2:


Useally it is because the string is not formatted correctly for encoding as an URL. Try to chop of bits of the string to find the offending part.



来源:https://stackoverflow.com/questions/3203842/nsurl-not-getting-allocatd-with-nsstring

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!