English 中文(简体)
InitWithContentsOfURL 似乎有“冗长”的问题。
原标题:initWithContentsOfURL seems to have issues with "long" URLs

I m facing a rather strange Issue when trying to load data from an XML-Webservice. The webservice allows me to pass separated identifiers within the URL-Request. It is therefore possible for the URL to become rather long (>240 characters). If I open said URL in firefox the response arrives as planned, if I execute the following code xmlData remains empty.

NSString *baseUrl = [[NSString alloc] initWithString:[[[[kSearchDateTimeRequestTV stringByReplacingOccurrencesOfString:@"{LANG}" withString:appLanguageCode] 
                                              stringByReplacingOccurrencesOfString:@"{IDENTIFIERS}" withString:myIdentifiers]
                                             stringByReplacingOccurrencesOfString:@"{STARTTICKS}" withString:[NSString stringWithFormat:@"%@", [[startTime getTicks] descriptionWithLocale:nil]]]
                                            stringByReplacingOccurrencesOfString:@"{ENDTICKS}" withString:[NSString stringWithFormat:@"%@", [[endTime getTicks] descriptionWithLocale:nil]]]];

NSLog(baseUrl); //looks good, if openend in browser, returnvalue is ok

urlRequest = [NSURL URLWithString:baseUrl];


NSString *xmlData = [NSString stringWithContentsOfURL:urlRequest encoding:NSUTF8StringEncoding error:&err]; //err is nil, therefore i guess everything must be ok... :(

NSLog(xmlData); //nothing... 

是否有任何限制,对你们任何人来说是否也存在同样的问题? 什么是好的工作?

感谢您的帮助

萨姆

最佳回答

Before passing baseURL to URLWithString you must ensure that it is a valid url otherwise it will return NULL. You can use the following line of code to encode non-valid characters to percent-escape sequence:

NSString *fixedURL = [baseURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; // or any other encoding

如果在URL中你通过无效特性,大多数浏览器实际上会自动这样做,因此这可能是月球工作的原因。

Claus

问题回答

暂无回答




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签