Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Understanding network.request parameters
Started by vonncc123 Jun 12 2018 11:55 PM

2 replies to this topic
network method post get
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

vonncc123

[GLOBAL: userInfoPane.html]
vonncc123
  • Contributor

  • 222 posts
  • Corona SDK

Good day, I would like to understand the Corona's way to send a GET and POST Method to my PHP.

On my POST Method everything is fine with this kind of code:

local function saveListener( event )
 
    if ( event.isError ) then
	print( "Network error: ", event.response )
    else
        print ( "RESPONSE: " .. event.response )
    end
end

local headers = {}
	                      
headers["Content-Type"] = "application/x-www-form-urlencoded"
headers["Accept-Language"] = "en-US"

local body = "filename=".. file .."&something=".. some)
	                     
local params = {}
params.headers = headers
params.body = body
network.request( "urltoPHPfile.php", "POST", saveListener, params )

There is no error here everything is okay but when I use the GET Method, I can't find my "filename" and "somnething" on the body parameters to my PHP, when I do it with HTML, it's okay.

 

Thanks in advance



[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 24,527 posts
  • Corona Staff

HTTP GET expects key-value pairs to be part of the URL. It does not use a "body" concept. URL's have a length limit, so it only works for URL's in the 256 max character limit. HTTP POST exists to allow you to send bigger blocks of data to your server script.

 

To use HTTP GET you would do:

local params = {}
params.headers = headers
network.request( "urltoPHPfile.php?filename=".. file .. "&something="..some, "GET", saveListener, params)

Rob



[TOPIC: post.html]
#3

vonncc123

[GLOBAL: userInfoPane.html]
vonncc123
  • Contributor

  • 222 posts
  • Corona SDK

Oh, so I did that, I thought there is another way other than the code you just showed. Thanks :)




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: network, method, post, get