开发者

NSURL from File -> Editing text of data then turn back into URL = NULL

开发者 https://www.devze.com 2023-04-09 20:48 出处:网络
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 NSUR

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>


You can't turn html source back into a URL.

You can sent the updated html to a UIWebView to display.

- (void)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消