使用Session启动Web URL

时间:2015-04-01 12:42:28

标签: ios objective-c uiwebview

我正在开发HTML网页。我正在创建会话ID。

我想使用相同的会话ID通过我的iOS应用程序打开该网站。

NSString *urlString = @"http://www.myserver.com:8080/Test/TestPage";
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[webview loadRequest:urlRequest];

是否可以使用iOS中附加的会话ID 启动网址?

1 个答案:

答案 0 :(得分:-1)

如果我不是以错误的方式理解它,您只想在请求中添加一些参数,在本例中为sessionID。在这种情况下,您应该这样做:

 NSURL *url = [NSURL URLWithString: @"http://www.myserver.com:8080/Test/TestPage"];
    NSString *body = [NSString stringWithFormat: @"sessionID=%@", @"val1"];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL: url];
    [request setHTTPMethod: @"POST"];
    [request setHTTPBody: [body dataUsingEncoding: NSUTF8StringEncoding]];
    [webView loadRequest: request];

另一方面,您可以使用AFNetworking Library来执行以下操作:

NSDictionary * parameters = @{@"sessionID"     : @"123"};
NSMutableURLRequest * mutableRequest = [self requestWithMethod:@"POST"
                                                          path:@"http://www.myserver.com:8080/Test/TestPage"
                                                    parameters:parameters];

无论如何,@ Popeye是对的,你需要在服务器中以某种方式管理它。