這是可能的。只需自己做網絡代碼,然後將生成的HTML轉儲到UIWebView。
// Do your POST
NSURL *url = [NSURL URLWithString:"http://stackoverflow.com"];
NSString *body = @"laadeedaa";
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod: @"POST"];
[request setHTTPBody: [body dataUsingEncoding:NSUTF8StringEncoding]];
// Dump the response to the UIWebView
[webView loadRequest:request];
如果你要處理顯示之前的響應,那麼你會想要做的線沿線的東西:
NSURLResponse *response = nil;
NSError *error = nil;
NSData *respData = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response
error:&error];
NSString *respString = [[[NSString alloc] initWithData:respData
encoding:NSUTF8StringEncoding] autorelease];
NSString *htmlString = [self doSomethingWith:respString];
[webView loadHTMLString:htmlString baseURL:@"http://stackoverflow.com"];
記住也請您可以使用JavaScript來控制瀏覽器:
- (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script
感謝您的快速回復。 NSMutableURLRequest是否會處理auth網絡cookie?或者它會發送請求 - 就像火,忘了? – dan 2010-01-14 01:24:58
我不知道說實話。我過去6個月一直在使用MonoTouch。蘋果有很好的文檔;否則,打開一個新的SO問題。 – 2010-01-14 02:55:22