来自文件的 NSURL ->编辑数据文本然后返回 URL = NULL
我有一个 html 文件,我想在显示之前动态编辑该文件以更改某些值。
我得到的文件很好,然后替换我想要的文本,仍然很好。但是当我将其转换回 NSURL 时,它显示 NULL 和 WebKitErrorDomain 错误 101。
这是代码:
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"html"];
NSURL *theURL = [NSURL fileURLWithPath:filePath isDirectory:NO];
NSError *error;
NSString* text = [NSString stringWithContentsOfURL:theURL encoding:NSASCIIStringEncoding error:&error];
NSString *newURL = @"SRC=\"http://75.25.157.90/nphMotionJpeg?Resolution=640x480&Quality=Standard\"";
text = [text stringByReplacingOccurrencesOfString:@"__SRC__" withString:newURL] ;
NSURLRequest *newRequest = [ [NSURLRequest alloc] initWithURL: [NSURL URLWithString:text] ];
[web loadRequest:newRequest];
我在 html 文件中有“__SRC__”,我想要将其替换为上面的 newURL 字符串...
任何指针都会很棒。我已经尝试了我能想到的一切...
---- 添加了 HTML 代码 ----
<HEAD>
<META HTTP-EQUIV="expires" CONTENT="0">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
<TITLE>ImageViewer</TITLE>
<META http-equiv="Content-Script-Type" content="text/javascript">
<META http-equiv="Content-Style-Type" content="text/css">
</HEAD>
<BODY onLoad="setParam();play();" BGCOLOR="#EFEFEF" TEXT="#ffffff"
LINK="#ffffff" VLINK="#ffffff" ALINK="#ffffff" TOPMARGIN="0" LEFTMARGIN="0" MARGINHEIGHT="0" MARGINWIDTH="0">
<INPUT TYPE=hidden NAME="Width" VALUE="640">
<INPUT TYPE=hidden NAME="Height" VALUE="480">
<INPUT TYPE=hidden NAME="Language" VALUE="0">
<INPUT TYPE=hidden NAME="Direction" VALUE="Direct">
<INPUT TYPE=hidden NAME="PermitNo" VALUE="514861200">
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0>
<TR>
<TD><INPUT TYPE=image NAME="NewPosition" __SRC__ WIDTH=320 HEIGHT=240 BORDER=0></TD>
</TR>
</TABLE>
</BODY>
</HTML>
I have an html file that I want to dynamically edit before displaying to change some of the values.
I get the file fine, then replace the text I want, still fine. But when I convert it back to a NSURL it shows NULL and WebKitErrorDomain error 101.
Here is the code:
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"html"];
NSURL *theURL = [NSURL fileURLWithPath:filePath isDirectory:NO];
NSError *error;
NSString* text = [NSString stringWithContentsOfURL:theURL encoding:NSASCIIStringEncoding error:&error];
NSString *newURL = @"SRC=\"http://75.25.157.90/nphMotionJpeg?Resolution=640x480&Quality=Standard\"";
text = [text stringByReplacingOccurrencesOfString:@"__SRC__" withString:newURL] ;
NSURLRequest *newRequest = [ [NSURLRequest alloc] initWithURL: [NSURL URLWithString:text] ];
[web loadRequest:newRequest];
I have "__SRC__" in the html file and I want to replace it with the newURL string above...
Any pointers would be great. I've tried everything I can think of...
---- Added HTML code ----
<HEAD>
<META HTTP-EQUIV="expires" CONTENT="0">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
<TITLE>ImageViewer</TITLE>
<META http-equiv="Content-Script-Type" content="text/javascript">
<META http-equiv="Content-Style-Type" content="text/css">
</HEAD>
<BODY onLoad="setParam();play();" BGCOLOR="#EFEFEF" TEXT="#ffffff"
LINK="#ffffff" VLINK="#ffffff" ALINK="#ffffff" TOPMARGIN="0" LEFTMARGIN="0" MARGINHEIGHT="0" MARGINWIDTH="0">
<INPUT TYPE=hidden NAME="Width" VALUE="640">
<INPUT TYPE=hidden NAME="Height" VALUE="480">
<INPUT TYPE=hidden NAME="Language" VALUE="0">
<INPUT TYPE=hidden NAME="Direction" VALUE="Direct">
<INPUT TYPE=hidden NAME="PermitNo" VALUE="514861200">
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0>
<TR>
<TD><INPUT TYPE=image NAME="NewPosition" __SRC__ WIDTH=320 HEIGHT=240 BORDER=0></TD>
</TR>
</TABLE>
</BODY>
</HTML>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法将 html 源代码转回 URL。
您可以将更新后的 html 发送到 UIWebView 进行显示。
或者您可以使用网络服务器来提供它。
但也许有术语细分,我不明白 html 是什么,请发布它或至少发布一个示例。
You can't turn html source back into a URL.
You can sent the updated html to a UIWebView to display.
Or you could server it with a web server.
But perhaps there is a terminology breakdown and I don't understand what the html is, please post it or at least a sample.