Created
June 2, 2013 07:55
-
-
Save n0bisuke/5692961 to your computer and use it in GitHub Desktop.
CoronaSDKでPOSTするサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--CoronaSDKでPOSTの実装 | |
--表示用のテキスト | |
local myPost = display.newText("(Waiting for response)", 0, 100, native.systemFont, 16) | |
local function networkListener( event ) | |
if ( event.isError ) then --通信が失敗した場合 | |
myPost.text = "Network error!" | |
else --通信が成功した場合 | |
myPost.text = event.response | |
end | |
end | |
--ヘッダ情報の設定 POSTの場合は必要らしい | |
local headers = {} | |
headers["Content-Type"] = "application/x-www-form-urlencoded" | |
headers["Accept-Language"] = "ja,en-us;q=0.7,en;q=0.3" | |
--bodyにパラメータと値を設定する | |
local body = "name=hogehoge&message=hugahuga" | |
local params = {} | |
params.headers = headers | |
params.body = body | |
local url = "http://example.com/mail.php" --POSTを受け取るサーバー側のアドレス | |
network.request(url, "POST", networkListener, params) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment