Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

network.request err with method POST
Started by luch Mar 25 2020 06:11 AM

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

luch

[GLOBAL: userInfoPane.html]
luch
  • Observer

  • 10 posts
  • Corona SDK

Greetings,

I try use CORONA + FLIGHT PHP.

I test with other methos, work fine.
When I always teste with POST, FLIGHT return method: GET.

This is a correct place to post this doubt?

Best regards.


 

index.php

<?php
require 'flight/Flight.php';

Flight::route('/', function(){
  $oo = new StdClass;
  $oo->hello = "Hello World!";
  $oo->request = Flight::request();
  echo json_encode ( $oo ) ;
});

Flight::start();

#1 Test whit PUT

network.request( "http://localhost/corona", "PUT", networkListener )

#1 Return

10:58:18.729  networkListener.Ok
10:58:18.729  table: 03A06508 {
10:58:18.729    [hello] => "Hello World!"
10:58:18.729    [request] => table: 03A06508 {
10:58:18.729                   [proxy_ip] => ""
10:58:18.729                   [referrer] => ""
10:58:18.729                   [data] => table: 03A06580 {
10:58:18.729                             }
10:58:18.729                   [ip] => "::1"
10:58:18.729                   [host] => "localhost"
10:58:18.729                   [query] => table: 03A06580 {
10:58:18.729                              }
10:58:18.729                   [url] => "/"
10:58:18.729                   [base] => "/corona"
10:58:18.729                   [type] => ""
10:58:18.729                   [method] => "PUT"
10:58:18.729                   [accept] => ""
10:58:18.729                   [user_agent] => ""
10:58:18.729                   [secure] => false
10:58:18.729                   [cookies] => table: 03A06580 {
10:58:18.729                                }
10:58:18.729                   [scheme] => "http"
10:58:18.729                   [files] => table: 03A06580 {
10:58:18.729                              }
10:58:18.729                   [length] => "0"
10:58:18.729                   [ajax] => false
10:58:18.729                 }
10:58:18.729  }

 

 

#2 Test with GET

network.request( "http://localhost/corona", "GET", networkListener )

# Return

11:04:20.421  networkListener.Ok
11:04:20.421  table: 0A1E74F0 {
11:04:20.421    [hello] => "Hello World!"
11:04:20.421    [request] => table: 0A1E74F0 {
11:04:20.421                   [proxy_ip] => ""
11:04:20.421                   [referrer] => ""
11:04:20.421                   [data] => table: 0A1E75B8 {
11:04:20.421                             }
11:04:20.421                   [ip] => "::1"
11:04:20.421                   [host] => "localhost"
11:04:20.421                   [query] => table: 0A1E75B8 {
11:04:20.421                              }
11:04:20.421                   [url] => "/"
11:04:20.421                   [base] => "/corona
11:04:20.421                   [type] => ""
11:04:20.421                   [method] => "GET"
11:04:20.421                   [accept] => ""
11:04:20.421                   [user_agent] => ""
11:04:20.421                   [secure] => false
11:04:20.421                   [cookies] => table: 0A1E75B8 {
11:04:20.421                                }
11:04:20.421                   [scheme] => "http"
11:04:20.421                   [files] => table: 0A1E75B8 {
11:04:20.421                              }
11:04:20.421                   [length] => 0
11:04:20.421                   [ajax] => false
11:04:20.421                 }
11:04:20.421  }
 
#Test with POST
network.request( "http://localhost/corona/ruth", "POST", networkListener )
#Return
11:06:02.494  networkListener.Ok
11:06:02.494  table: 0A3BF5B8 {
11:06:02.494    [hello] => "Hello World!"
11:06:02.494    [request] => table: 0A3BF5B8 {
11:06:02.494                   [proxy_ip] => ""
11:06:02.494                   [referrer] => ""
11:06:02.494                   [data] => table: 0A3BF6A8 {
11:06:02.494                             }
11:06:02.494                   [ip] => "::1"
11:06:02.494                   [host] => "localhost"
11:06:02.494                   [query] => table: 0A3BF6A8 {
11:06:02.494                              }
11:06:02.494                   [url] => "/"
11:06:02.494                   [base] => "/corona"
11:06:02.494                   [type] => ""
11:06:02.494                   [method] => "GET"
11:06:02.494                   [accept] => ""
11:06:02.494                   [user_agent] => ""
11:06:02.494                   [secure] => false
11:06:02.494                   [cookies] => table: 0A3BF6A8 {
11:06:02.494                                }
11:06:02.494                   [scheme] => "http"
11:06:02.494                   [files] => table: 0A3BF6A8 {
11:06:02.494                              }
11:06:02.494                   [length] => 0
11:06:02.494                   [ajax] => false
11:06:02.494                 }
11:06:02.494  }


[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,680 posts
  • Enterprise

I have two answers...

 

First, for a long time PHP wouldn't necessarily populate the $_POST[] associative array. You had to set the right content headers to get it to recognize it. You can do a Google search for PHP doesn't populate $_POST and look at the advice there. This isn't a Corona specific issue.

 

Secondly, POST expects a body be passed to it. GET has all of it's key-value pairs as part of the URI. POST expects a body of key-value pairs (assuming you picked the right content type). If your server can handle JSON you would set the Content-type header to "application/json". You can research the appropriate Content-type header and provide the data via the body.

 

Rob



[TOPIC: post.html]
#3

luch

[GLOBAL: userInfoPane.html]
luch
  • Observer

  • 10 posts
  • Corona SDK

@Rob Miracle,

Thank you for reply.

This knowledge about $_POST was unknow for me.

I want find ways to solve my problems, I can use anotheer ways without problem, like other methods.

Best regards.




[topic_controls]
[/topic_controls]