Javascript 页面未根据来自iOS的URL请求重定向
我正试图用Swift从iOS发出一个url请求,并通过url将一些数据发送到一种PHP服务器Javascript 页面未根据来自iOS的URL请求重定向,javascript,php,ios,swift,Javascript,Php,Ios,Swift,我正试图用Swift从iOS发出一个url请求,并通过url将一些数据发送到一种PHP服务器 let url = URL(string: "http://www.mybadservice.com/redirectToAction.php?id=\(id)") print(stringUrl) var mutableRequest = URLRequest(url: url!) URLSession.shared.dataTask(with: mutableRequ
let url = URL(string: "http://www.mybadservice.com/redirectToAction.php?id=\(id)")
print(stringUrl)
var mutableRequest = URLRequest(url: url!)
URLSession.shared.dataTask(with: mutableRequest) { (data, urlResponse, error) in
if error != nil {
print("Error running this ...")
return
}
let statusCode = urlResponse as? HTTPURLResponse
print("HTTP RESPONSE : \(statusCode?.statusCode)")
let dataString = String(data: data!, encoding: .utf8)
print("DATA : \(dataString)")
}.resume()
当我将数据发送到redirectToAction.php时,它应该使用GET获取数据,创建url并使用javascript重定向到另一个页面,而这个页面做了一些工作
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
location.href ="./DoSomeWork.php?id=passedId"; /*Where pasedId is the paramether I send by url, I don't now how exactly passedId is linked together from php to javascript because I have not access to the code */
</script>
</body>
location.href=“./DoSomeWork.php?id=passedId”/*pasedId是我通过url发送的参数,我现在不知道passedId是如何从php链接到javascript的,因为我无法访问代码*/
现在,它不仅在我做出响应时起作用。我试着复制应用程序生成的url并将其粘贴到浏览器中,效果非常好。此外,应用程序中的请求返回200个http代码并打印整个html页面。这将不起作用,因为php是服务器端,服务器无法重定向到不相关浏览器中的页面 相信我,如果你再看一遍你的问题,一年后你会流泪:)