错误:“HttpGetData.Type没有名为'url'的成员”

时间:2015-06-25 08:41:30

标签: swift

我想测试HTTP POST,但它显示了这个错误:

  

HttpGetData.Type'没有名为'url'的成员

当我在ViewController上输入它时,它有效吗?

是初始化问题吗?

import Foundation
public class HttpGetData{

    let url = NSURL( string: "https://210.61.209.194:8443/SmarttvWebServiceTopmsoApi/")

    let request = NSMutableURLRequest((URL : url)!)
    request.HTTPMethod = "POST"
    let postString : String = "id=13&name=Jack"
    request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding)
    let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {
        data, response, error in

        if error != nil {
            println("error=\(error)")
            return
        }

        println("response = \(response)")

        let responseString = NSString(data: data, encoding: NSUTF8StringEncoding)
        println("responseString = \(responseString)")
    }
    task.resume()

}

0 个答案:

没有答案