调用PHP API时网络连接丢失

时间:2015-07-14 15:23:38

标签: ios objective-c swift

    var SubmitDic = NSMutableDictionary ()
    SubmitDic.setObject (loginMerged, forKey: "module" )
    SubmitDic.setObject (kedahE-tutorApp, forKey: "wsKey" )
    SubmitDic.setObject (112211, forKey: "passwd" )
    SubmitDic.setObject (form04, forKey: "userName" )

    var request : NSMutableURLRequest = NSMutableURLRequest()
    request.URL = NSURL(string: http://kedah-etutor.com/component/module/ws_function2.php)
    request.HTTPMethod = "POST"
    request.HTTPBody = NSJSONSerialization.dataWithJSONObject(SubmitDic, options: NSJSONWritingOptions() , error: nil)
    println(NSJSONSerialization.dataWithJSONObject(SubmitDic, options: NSJSONWritingOptions() , error: nil)?.description)
    request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")

    NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue(), completionHandler:{ (response:NSURLResponse!, data: NSData!, error: NSError!) -> Void in
        var error : AutoreleasingUnsafeMutablePointer<NSError?> = nil

        if data != nil
        {
        }

我试图调用php json Web服务,但是它返回null数据并且错误描述一直提到“网络连接丢失”。此外,在Java中,HttpClient框架可以很好地与PHP Web服务配合使用。

0 个答案:

没有答案