2017-07-24 22:18
浏览 99


I'm trying to make a URLRequest from iOS with Swift and I send some data by the url to a kind of PHP server.

let url = URL(string: "\(id)")


    var mutableRequest = URLRequest(url: url!)

    URLSession.shared.dataTask(with: mutableRequest) { (data, urlResponse, error) in
        if error != nil {
            print("Error running this ...")

        let statusCode = urlResponse as? HTTPURLResponse
        print("HTTP RESPONSE : \(statusCode?.statusCode)")
        let dataString = String(data: data!, encoding: .utf8)
        print("DATA : \(dataString)")

When I send the data to redirectToAction.php it should gets the data using GET, makes a url and redirect to another page using javascript and this page does some work.


    <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 */

Now it does not works just when I make a urlResponse. I tried to copy the url generated by the app and paste it in the browser and it works perfectly. Also the request in the app returns a 200 http code and prints the whole html page.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • drsh30452
    drsh30452 2017-07-25 16:45

    This will not work, because php is server side and the server can not redirect to a page in a unrelated browser.

    Trust me, in one year you will cry tears if you read your question again :)

    点赞 评论