Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 将登录凭据传递到UIWebView_Ios_Swift_Uiwebview - Fatal编程技术网

Ios 将登录凭据传递到UIWebView

Ios 将登录凭据传递到UIWebView,ios,swift,uiwebview,Ios,Swift,Uiwebview,我有一个应用程序内登录页面,可以获取SID。如何将这些登录凭据传递到Swift中显示的UIWebView中 编辑:我原以为我可以用网址中的SID将URL加载到我的webview中,但我在这样做时出错。可能您正在UIWebView中显示一个网站(例如www.foo.com),并希望将SID传递到UIWebView以登录www.foo.com 您需要使用HTMLBody和HTTPMethod正确设置NSMutableURLRequest,以实现此目的。将SID传递给登录名的方法是通过查询参数 var

我有一个应用程序内登录页面,可以获取SID。如何将这些登录凭据传递到Swift中显示的UIWebView中


编辑:我原以为我可以用网址中的SID将URL加载到我的webview中,但我在这样做时出错。

可能您正在
UIWebView
中显示一个网站(例如www.foo.com),并希望将SID传递到
UIWebView
以登录www.foo.com

您需要使用
HTMLBody
HTTPMethod
正确设置
NSMutableURLRequest
,以实现此目的。将SID传递给登录名的方法是通过查询参数

var url = NSURL(string: "http://www.foo.com")

var request = NSMutableURLRequest(URL: url!)

// usually to login you send a POST with the user's credentials
request.HTTPMethod = "POST"

// this is where you would assign the SID (from a UITextView, etc.)
var sid = "1234" // getSid()

var bodyData = "SID=\(sid)"

// encode the query params as UTF8
request.HTTPBody = bodyData.dataUsingEncoding(NSUTF8StringEncoding)

// this will load the UIWebView by sending the POST with the query string:
// http://www.foo.com/?SID=1234
webView.loadRequest(request)

假设您正在
UIWebView
中显示一个网站(例如www.foo.com),并希望将SID传递给
UIWebView
以登录www.foo.com

您需要使用
HTMLBody
HTTPMethod
正确设置
NSMutableURLRequest
,以实现此目的。将SID传递给登录名的方法是通过查询参数

var url = NSURL(string: "http://www.foo.com")

var request = NSMutableURLRequest(URL: url!)

// usually to login you send a POST with the user's credentials
request.HTTPMethod = "POST"

// this is where you would assign the SID (from a UITextView, etc.)
var sid = "1234" // getSid()

var bodyData = "SID=\(sid)"

// encode the query params as UTF8
request.HTTPBody = bodyData.dataUsingEncoding(NSUTF8StringEncoding)

// this will load the UIWebView by sending the POST with the query string:
// http://www.foo.com/?SID=1234
webView.loadRequest(request)

你犯了什么错误?另外,当您说“在web地址中使用SID”时,您是如何将其放置在web地址中的?您会遇到什么错误?另外,当您说“在web地址中使用SID”时,如何将其放置在web地址中?