开发者

UIWebView webViewDidStartLoad is called with request which properties are null

I am currently debugging a UIWebView in order to get some information to improve performance (on server and iPhone). I noticed that after calling loadRequest: the callback

- (void)webViewDidStartLoad:(UIWebView *)webView_ 

is called, however each parameter of the request is null.

I am using the following statement:

    - (void)webViewDidStartLoad:(UIWebView *)webView_{
    NSLog(@"%@ \t St开发者_JAVA百科art Request: %@ \n absolute: %@ \n Method: %@ \n Parameters: %@ \n Port: %@ \n Query: %@ \n Header Fields: %@ \n HTTPBody: %@ \n HTTPBodyStream: %@", [NSDate date], [[webView_ request] mainDocumentURL], [[[webView_ request] mainDocumentURL] absoluteString], [[webView_ request] HTTPMethod], [[[webView_ request] mainDocumentURL] parameterString], [[[webView_ request] mainDocumentURL] port], [[[webView_ request] mainDocumentURL] query], [[webView_ request] allHTTPHeaderFields], [[webView_ request] HTTPBody], [[webView_ request] HTTPBodyStream]);
}

The output is:

 2011-05-11 17:15:34 +0200    Start Request: (null) 
 absolute: (null) 
 Method: GET 
 Parameters: (null) 
 Port: (null) 
 Query: (null) 
 Header Fields: {
} 
 HTTPBody: (null) 
 HTTPBodyStream: (null)

Is there any explanation for this behavior or anything to fix this?

The page loads fine, however the request loading nothing seems to take about 30 seconds which I try to avoid.

edit: some additional information about loading the webview. I am calling a method which adds the webview to the UIView and loads the URL

    UIWebView * web = [[UIWebView alloc] initWithFrame:CGRectMake(indent, topindent+indent, screenSize.width-2*indent, screenSize.height-2*indent-topindent)];
     web.delegate = self;
    [view addSubview:web];
    NSURLRequest * someUrl = [NSURLRequest requestWithURL:[NSURL URLWithString:
@"some_URL"]];
    [web loadRequest: someUrl];


The reason you're not seeing a request is that the request property of the webview isn't assigned until the request has been loaded. This is likely to only show the actual displayed request, after all redirects. If you want the initial request object, before redirects etc, use ToddH's answer. For the final request, you will have to check it in webViewDidFinishLoad.


Well, after struggling with this same issue I discovered that the solution is to use this UIWebViewDelegate method:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType

It gets called right before viewDidStartLoad and is passed the request object that the view will load with.


The one thing you didn't check is the request URL property. Check that, and see what you get:

[[[webView_ request] URL] absoluteString]

Edit:

It looks like you might be having problems with autoreleased objects. Try creating the NSURL separate fromt he NSURLRequest:

NSURL *myURL = [NSURL URLWithSTring:@"some_URL"];
NSURLRequest *someUrl = [NSURLRequest requestWithURL:myURL];
[web loadRequest:someUrl];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜