1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
@H_502_70@
25
26
27
28
29
30
|
//保存分数
{
var
url:
NSURL
!
url =
(string:urlString)
request =
NSMutableURLRequest
(
URL
:url)
//编码POST数据
postData = body.dataUsingEncoding(
NSUTF8StringEncoding
)
//保用 POST 提交
request.
HTTPMethod
"POST"
HTTPBody
= postData
//响应对象
response:
NSURLResponse
?
do{
//发出请求
received:
NSData
? = try
NSURLConnection
.sendSynchronousRequest(request,
returningResponse: &response)
datastring =
NSString
(data:received!,encoding:
)
print
(datastring)
}catch
error
as
NSError
{
//打印错误消息
(error.code)
(error.description)
}
}
|
import
UIKit
{
//保存分数
)
{
!
(string:urlString)
:url)
//编码POST数据
NSASCIIStringEncoding
)
//保用 POST 提交
"POST"
= postData
conn:
!
conn =
(request: request,delegate:
self
)
conn.start()
(conn)
}
connection(connection:
)
(
"请求成功!"
);
(response)
}
)
{
"请求成功1!"
);
(data:data,monospace!important; min-height:auto!important">)
(datastring)
}
connectionDidFinishLoading(connection:
)
{
"请求成功2!"
);
}
}
|
//获取分数
"http://hangge.com/getscore.php?user=\(user)"
"GET"
!
)
conn.start()
(conn)
}
)
{
);
(response)
)
{
);
)
(datastring)
//解析 JSON 数据
do {
json :
AnyObject
! = try
NSJSONSerialization
.
JSONObjectWithData
(data,
options:
NSJSONReadingOptions
AllowFragments
)
(score)
{
//打印错误消息
(error.code)
(error.description)
}
}
)
{
);
}
}
|