如何将数据发布到我自己的服务器。我可以从中获取数据,但无法添加数据。获取的代码如下:
local function networkListener( event )
if ( event.isError ) then
print( "Network error!")
else
local json=event.response
local length=string.len(json)
json=string.sub(json, 50, (length-1));
jsonTable=JSON.encode(json)
local t = jsonTable
print(jsonTable)
-- Go through the array in a loop
for key in pairs(t) do
-- Here you can do whatever you like with the values
print(t[key]["AuthorID"])
print(t[key]["AuthorName"])
--print(t[key]["returnvalue3"])
end
end
end
local remoteFeed="http://www.xtremeesolutions.com/xesapps/webservice/readauthors.php"
network.request(remoteFeed, "GET", networkListener)
--And trying code to post data is
local function postData(e)
if (e.isError)then
print("Error ");
else
print("Error ".. e.response);
end
end
local params = {
body = query
}
network.request(remoteFeed, "POST",postData,params))
上面的代码没有给出任何错误但也没有插入值。请建议我解决这个问题。
答案 0 :(得分:0)
我认为您应该使用“POST”而不是“GET”,请参阅以下代码:
...
local remoteFeed="http://www.xtremeesolutions.com/xesapps/webservice/readauthors.php"
network.request(remoteFeed, "POST", networkListener, params)
也许您还应该在以下部分查看此链接http://docs.coronalabs.com/api/library/network/request.html:使用自定义标题的HTTP POST
<强> EDITED 强>
句柄值的循环应为:
if ( event.isError ) then
print( "Network error!")
else
...
for key in pairs(t) do
postData = t[key]["AuthorID"] .. "=" .. t[key]["AuthorName"]
end
local params = {}
params.body = postData
local remoteFeed="http://www.xtremeesolutions.com/xesapps/webservice/readauthors.php"
network.request(remoteFeed, "POST", networkListener, params)
end
这些行应该在其他范围内收集。