2012-02-13 9 views
0

コロナSDKでnetwork.request関数をライブウェブサーバーで使用する際に問題が発生しています。それは私のlocalhost上でうまく動作しますが、アプリケーションがゼロ値を返すリモートサーバと通信するコードを変更すると分かります。ルア/コロナSDKでのネットワークリクエスト

これは.luaファイル内の私が使用していたコード

local function networkListener(event) 
    if (event.isError) then 
     print("Network error!") 
    else 
     print ("RESPONSE: " .. event.response) 
     local data = json.decode(event.response) 
     responseText.text = data.result; 
     messageText.text = data.message; 
    end 
end 

------------------ 
--Send the request to the website to have the user Registered. 
------------------ 
function AddUser (username, email, password, Device_Type, Device_ID) 
     --Register Local 
     network.request("http://localhost/MobileApp/Register.php?loginid=" .. mime.b64(username) .. "&email=" .. mime.b64(email) .. "&password=" .. mime.b64(password) .. "&Device_Type=" .. mime.b64(Device_Type) .. "&Device_ID=" .. mime.b64(Device_ID), "GET", networkListener) 
end 

これは、PHPサーバー・コードがJSONデータの形で返すべきである:

$result = array(); 
    $result["result"] = 200; 
    $result["message"] = "Sucessfully Registered"; 
    echo json_encode($result); 
    mysql_free_result($dbresult); 
    exit;  

それとも、この場合要求は失敗しました。

$result = array(); 
    $result["result"] = 401; 
    $result["message"] = "Please try another Username"; 
    echo json_encode($result); 
    mysql_free_result($dbresult); 
    exit; 

私はので、私はこれだけのレイテンシの問題であり、LUAコードが待っていないことを仮定することができます私のPCからブラウザに直接URLを入力すると期待される結果

{"result":200,"message":"Sucessfully Registered"} 

を取得しています戻り値。 何が起こっているのか、この問題を解決する方法が分かっていれば、私は最も感謝しています。

よろしく グレン

+0

:私はまだ他の誰かが同様の問題を持っている包みコードである。ここ

インフォアJSONを解析するためにコロナでJSONデコーダを使用します開いたままではありません。 – lhf

答えて

0

は、私は、ダウンロードのためのコロナをバイパスし、ちょうどLUAコードを使用して作業、それを取得することになりました。その答えにあなたのソリューションを移動し、問題がないように、それを受け入れてください

local http = require("socket.http") 
local json = require("json") 


local URL = "http://localhost/MobileApp/Register.php?loginid=" .. mime.b64(username) .. "&email=" .. mime.b64(email) .. "&password=" .. mime.b64(password) .. "&Device_Type=" .. mime.b64(Device_Type) .. "&Device_ID=" .. mime.b64(Device_ID); 
local response = http.request(URL) 

if response == nil then 
    print("No Dice") 
else 
    local data = json.decode(response) 
    print(data.result); 
    print(data.message);  
end 
+0

このスレッドがまだ生存している場合、私はこれに関して質問をします。 非同期の種類であるため、Galaxyタブなどのデバイスに実行されたときに問題が発生しますか? 私はそれを使用したとき、それはただ凍ります。何故ですか? – gadss

関連する問題