initWithUrl不适用于问号

时间:2013-07-24 20:04:17

标签: ios objective-c ios4

NSURL *urlString = [NSURL URLWithString:urlAddress];

//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:urlString];

//Load the request in the UIWebView.
[self.webview loadRequest:requestObj];

我有上面的代码。出于某种原因,例如“http://linkedin.com/view?id=3”之类的网址,例如带有问号的网址未在网页浏览中正确加载。我该怎么办?

1 个答案:

答案 0 :(得分:0)

试试这个

 NSURL *url = [NSURL URLWithString: @"http://your_url.com"];
    NSString *body = [NSString stringWithFormat: @"arg1=%@&arg2=%@", @"val1",@"val2"];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL: url];
    [request setHTTPMethod: @"POST"];
    [request setHTTPBody: [body dataUsingEncoding: NSUTF8StringEncoding]];
    [webView loadRequest: request];