dongzhi4690 2016-11-02 04:23
浏览 12
已采纳

什么都没有发布到我的PHP脚本

I have a php script on my server and I am trying to post data from my ios app, but when I print the post variables I get a nil. Any idea why that is?

Swift

let url: NSURL = NSURL(string: "https://xxxxxx.com/myFile.php")!
    let request:NSMutableURLRequest = NSMutableURLRequest(url: url as URL)
    let bodyData = "username=\(username.text)&password=\(password.text)"
    request.httpMethod = "POST"
    request.httpBody = bodyData.data(using: String.Encoding.utf8);
    request.setValue("application/x-www-form-urlencoded; charset=utf-8", forHTTPHeaderField: "Content-Type")
    NSURLConnection.sendAsynchronousRequest(request as URLRequest, queue: OperationQueue.main)
    {
        (response, data, error) in
        let responseString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
        //
        print("response \(responseString)")

    }

PHP

print_r($_POST); //prints: ([username] => xxxxxx [password] => yyyyyy)
json_encode($postVarUser);
json_encode($postVarPass);
  • 写回答

1条回答 默认 最新

  • dotxxh0998 2016-11-02 04:33
    关注

    May be it is the problem of echo($postUser); just use json_encode($postUser);

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化