Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7995123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:19:06+00:00 2026-06-04T14:19:06+00:00

I have a Django that having API for JSON, and I want it to

  • 0

I have a Django that having API for JSON, and I want it to get it in my Lua (Corona SDK) project.

if I CURL my Django project.

curl -l -X POST -d "message=getstrings" http://127.0.0.1:8000/api/getstrings/

this will return:

{
    "message": "Something good happened on the server!", 
    "data": [
        {
            "code": "003", 
            "doc1": "sd.doc", 
            "title": "Test", 
            "artist": "ABBA", 
            "img": "sd.png", 
            "genre": "Pop"
        }, 
        {
            "code": "004", 
            "doc1": "sdsd.doc", 
            "title": "sdf", 
            "artist": "ABBA", 
            "img": "sdsd.png", 
            "genre": "Pop"
        }
    ], 
    "success": true
}

i have a problem in post method for json in Lua. i want the returned json will be get in Lua.

i try this in my Lua.

local response = {}
local r, c, h = http.request{
  url= "http://127.0.0.1:8000/api/getstrings/",
  method = "POST",
  headers = {
    ["content-length"] = "",
    ["Content-Type"] = "application/x-www-form-urlencoded"
  },
  source = ltn12.source.string(post),
  sink = ltn12.sink.table(response)

}
local path = system.pathForFile("r.txt", system.DocumentsDirectory)
local file = io.open (path, "w")

file:write (response[1] .. "\n")
io.close (file)

when i open r.txt:

i got this …

File "home/myhome/workspace/djangoproj/api/handlers.py", line 21, in create
  if attrs['message'] == 'getstrings':

KeyError: 'message'

i know what cause of the error because message and its value did not passed by Lua.
my question is that what is the equivalent code like this CURL

curl -l -X POST -d "message=getstrings" http://127.0.0.1:8000/api/getstrings/

in Lua (Corona SDK) so that the Lua can get and download the returned Json? is my code in my Lua is correct?

do anyone have an idea about my case?
thanks in advance …

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T14:19:08+00:00Added an answer on June 4, 2026 at 2:19 pm

    Why not use the network.request function provided by Corona?
    It is asynchronous as well.

    local function listener(event)
        print(event.response)
        print(event.isError)
        print(event.status)
    end
    
    
    local url = "http://127.0.0.1:8000/api/getstrings/"
    
    local body = "message=getstrings"
    
    local headers = {}
    headers["content-length"] = body:len(),
    headers["Content-Type"] = "application/x-www-form-urlencoded"
    
    
    
    local postData = {}
    postData.body = body
    postData.headers = headers
    
    network.request(url,"POST",listener,postData)
    

    Have a read here
    http://developer.anscamobile.com/reference/index/networkrequest

    EDIT

    If you REALLY want to use http.request then you can do this.

    local url = "http://127.0.0.1:8000/api/getstrings/"
    local body = "message=getstrings"
    local headers = {
        ["content-length"] = body:len(),
        ["Content-Type"] = "application/x-www-form-urlencoded"
      }
    
    local response = {}
    local r, c, h = http.request{
      url= url,
      method = "POST",
      headers = headers,
      source = ltn12.source.string(body),
      sink = ltn12.sink.table(response)
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a django project that I have been working on as a solo
I have a django view that returns HTTP 301 on a curl request: grapefruit:~
I have a Django template that I want to extend in multiple places. In
I have a Django app that uses MySQL as a backend. I'm having difficulties
I have a django project that uses a sqlite database that can be written
I'm a django newbie and have been having a problem. In my project root
It seems that all roads lead to having to use PyISAPIe to get Django
Newbie question. I have Django models that look like this: class Video(models.Model): uploaded_by =
I have a Django app that gets it's data completely from an external source
I have a Django form that uses a different number of fields based on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.