network.request

I had no problems with it till now.

This is the url:

https://admin.appnext.com/offerWallApi.aspx?id=ff802456-796b-4645-9b11-b3b2d6bc4374&cnt=5&type=json

Now, if I call this like

    local appNextURL = "https://admin.appnext.com/offerWallApi.aspx"     local appNextID = "ff802456-796b-4645-9b11-b3b2d6bc4374"     local cnt=1     local params = {}     params.body = "id=" .. appNextID .. "&cnt=" .. cnt .. "&type=json"     network.request(appNextURL, "GET", networkListenerAppNext, params)  

I am getting a response as if there where no parameters in the request.

But if I put the parameters in the url, all is fine:

local appNextURL = "https://admin.appnext.com/offerWallApi.aspx?id=ff802456-796b-4645-9b11-b3b2d6bc4374&cnt=5&type=json"  

And idea why is that?

Generally using params.body indicates you’re trying to do a POST request.  GET requests usually have the parameters as part of the URL.  So construct the URL with the parameters and don’t pass in the params like that.

Rob

I have tried with POST and got same behavior.

Regards,
Damir.

Do you know that the server script actually handles POST requests or only GET requests?

Don’t have that information.

As I wrote, I manged it to work by passing the url with parameters.

I am only curious why it doesn’t work with params.body.

Well the nature of a “GET” request is that it does not look for anything in the body. It just processes the URL and returns the result.

When you want to pass some information in the body of the request you need to specify the proper headers like content_type, content_length, content_encoding (if applicable), … ,pass the information in the body and call the server with a “POST” request. This however is not processed trivialy by any server script or service. It has to be written to process it and the data passed in the body has to be recognised by the server in order for it to be able to process it properly.

When a web app developer creates a script, be it in PHP, ASP etc.  They have to code it to either respond to a GET request or a POST request.  They are quite different in how they work.  A GET request uses key-value pairs as part of the URL.  A POST request uses key-value pairs written on the data stream after the server get’s the URL.

In the Corona world, params.body is the content that is sent on the data stream for POST requests.  If your script is expecting GET, then POST won’t send the data the way the script is looking for it.  If your script is expecting POST and the key-value pairs are all part of the URL, then it won’t know how to handle it.

In other words, it’s your responsibility to know what the server script expects and provide the data in a format it’s expecting.

Thank you for the clarification.

Regards,
Damir.

Generally using params.body indicates you’re trying to do a POST request.  GET requests usually have the parameters as part of the URL.  So construct the URL with the parameters and don’t pass in the params like that.

Rob

I have tried with POST and got same behavior.

Regards,
Damir.

Do you know that the server script actually handles POST requests or only GET requests?

Don’t have that information.

As I wrote, I manged it to work by passing the url with parameters.

I am only curious why it doesn’t work with params.body.

Well the nature of a “GET” request is that it does not look for anything in the body. It just processes the URL and returns the result.

When you want to pass some information in the body of the request you need to specify the proper headers like content_type, content_length, content_encoding (if applicable), … ,pass the information in the body and call the server with a “POST” request. This however is not processed trivialy by any server script or service. It has to be written to process it and the data passed in the body has to be recognised by the server in order for it to be able to process it properly.

When a web app developer creates a script, be it in PHP, ASP etc.  They have to code it to either respond to a GET request or a POST request.  They are quite different in how they work.  A GET request uses key-value pairs as part of the URL.  A POST request uses key-value pairs written on the data stream after the server get’s the URL.

In the Corona world, params.body is the content that is sent on the data stream for POST requests.  If your script is expecting GET, then POST won’t send the data the way the script is looking for it.  If your script is expecting POST and the key-value pairs are all part of the URL, then it won’t know how to handle it.

In other words, it’s your responsibility to know what the server script expects and provide the data in a format it’s expecting.

Thank you for the clarification.

Regards,
Damir.