|
|
#1 |
|
How to request HTML page with "Loading..."
I am using NSURLCoeection to request HTML page, when I show it in UIWebView, the main contents can't be loaded and page is showing "読み込み中...", you can check attachment though there is Japanese for "Loading...". I checked source, there is somethings as below:
Code:
<div id="Tables"><div class="load_data"><span>読み込み中</span></div></div> Code:
- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse
__________________
iPad Mini 32GB, iPhone 4S 16GB, iPad1 32GB, Mac mini 2.53GHz 4GB 320GB, ThinkPad T60 MyApp: Market Event v1.9.2 Last edited by mikezang; Dec 12, 2012 at 07:22 AM. |
|
|
|
0
|
|
|
#2 |
|
What do you expect?
What have you tried? A single method name isn't good enough. Show us your implementation. |
|
|
|
0
|
|
|
#3 | |
|
Quote:
Code:
NSURL *url = [NSURL URLWithString:[self prefixForURLString:_htmlUrl.text]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
_connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
Code:
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
_htmlData = [[NSMutableData alloc] initWithData:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
[_htmlData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
NSLog(@"");
NSString *error_str = [error localizedDescription];
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"RequestError"
message:error_str
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSString *htmlString = [[NSString alloc]
initWithData:_htmlData
encoding:NSUTF8StringEncoding;
[_htmlSource loadHTMLString:htmlString baseURL:nil];
}
- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse
{
if (redirectResponse) {
NSMutableURLRequest *r = [request mutableCopy]; // original request
[r setURL: [request URL]];
return r;
}
else {
return request;
}
}
__________________
iPad Mini 32GB, iPhone 4S 16GB, iPad1 32GB, Mac mini 2.53GHz 4GB 320GB, ThinkPad T60 MyApp: Market Event v1.9.2 |
||
|
|
0
|
|
|
#4 |
|
The web page probably has relative links inside it and you don't set the baseURL so the web view doesn't know where to look for those assets.
Either just send the original link to the web view and let it load the page or you need to set the baseURL. |
|
|
|
0
|
|
|
#5 |
|
Where should I put a real baseURL?
__________________
iPad Mini 32GB, iPhone 4S 16GB, iPad1 32GB, Mac mini 2.53GHz 4GB 320GB, ThinkPad T60 MyApp: Market Event v1.9.2 |
|
|
|
0
|
|
|
#6 |
|
Code:
[_htmlSource loadHTMLString:htmlString baseURL:nil]; |
|
|
|
0
|
|
|
#7 |
|
That is no problems, my question is not HTML Web Viewer but HTML source view.
__________________
iPad Mini 32GB, iPhone 4S 16GB, iPad1 32GB, Mac mini 2.53GHz 4GB 320GB, ThinkPad T60 MyApp: Market Event v1.9.2 |
|
|
|
0
|
|
|
#8 |
|
You download a web page's html into a string and then ask the webview to load the html string. If there are relative paths in the html how will the web view know what web site to use to find the resources at those relative paths?
For example if I look at the page source for the main page of this forum I see html code like this Code:
<a href="subscription.php?do=addsubscription&f=135" rel="nofollow">Subscribe to This Forum</a> |
|
|
|
0
|
|
|
#9 | |
|
Quote:
My question is how can I get whole source including JavaScript, redirect and anything else, just like what I viewed in browser, how can I do? May I make sense?
__________________
iPad Mini 32GB, iPhone 4S 16GB, iPad1 32GB, Mac mini 2.53GHz 4GB 320GB, ThinkPad T60 MyApp: Market Event v1.9.2 |
||
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 12:15 AM.







Linear Mode
