# network.request post not sending data - what am I doing wrong?!

**URL:** <https://forums.solar2d.com/t/network-request-post-not-sending-data-what-am-i-doing-wrong/347663>\
**Category:** Game Networking\
**Created:** [May 25, 2018, 12:50pm UTC](https://forums.solar2d.com/t/network-request-post-not-sending-data-what-am-i-doing-wrong/347663 "2018-05-25T12:50:22Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Milner99](https://forums.solar2d.com/user_avatar/forums.solar2d.com/milner99/32/2091_2.png) [@Milner99](https://forums.solar2d.com/u/Milner99)\
**Post date:** [May 25, 2018, 12:50pm UTC](https://forums.solar2d.com/t/network-request-post-not-sending-data-what-am-i-doing-wrong/347663/1 "2018-05-25T12:50:22Z")

</div>

Hi All,

I have some code that saves a display object from the screen to the TemporaryDirectory - that’s working fine.

Reading the jpg back into the a variable - that’s working fine

useing mime.b64 to convert the above variable into a base64 variable - that’s working fine

Then I create a network request using the code below but it seems that the POST isn’t posting anything at all…any thoughts?

```
-- \_filename = specified above and is a valid filename. local \_file\_obj\_path = system.pathForFile(\_filename, system.TemporaryDirectory) local \_file\_obj = io.open(\_file\_obj\_path, rb) local \_file\_obj\_data = \_file\_obj:read("\*a") io.close(\_file\_obj) \_file\_obj=nil local \_file\_b64 = mime.b64(\_file\_obj\_data) local \_file\_obj\_size = string.len(\_file\_b64) -- post to CMS local p\_params = {} local headers = {} headers["Content-Type"] = "multipart/text" headers["Accept-Language"] = "en-US" p\_params.headers = headers p\_params.progress = "upload" p\_params.body = "hash="..string.urlEncode(hash).."&title="..string.urlEncode(text\_comments.text).."&user\_id=".. globalData.config\_table.user.id .. "&image\_name=" .. string.urlEncode(\_filename).."&image\_base64="..string.urlEncode(\_file\_b64) network.request("http://www.....com/index.php?user\_id=16", "POST", uploadListener, p\_params)

```

My Upload listener get the response from the PHP file, the $\_GET[‘user\_id’] is coming through fine but literally nothing in the $\_POST at all.

Also tried multiple different Content-types and not including any headers - nothing makes a difference.

\_file\_obj\_size is the size of the image( roughly of course as the base64 encoding adds a few characters here and there)

HELP!&nbsp;

Many thanks

Chris.

---

<div class="post-metadata">

**Author:** ![vlads](https://forums.solar2d.com/user_avatar/forums.solar2d.com/vlads/32/29_2.png) [@vlads](https://forums.solar2d.com/u/vlads)\
**Post date:** [May 25, 2018, 2:59pm UTC](https://forums.solar2d.com/t/network-request-post-not-sending-data-what-am-i-doing-wrong/347663/2 "2018-05-25T14:59:47Z")

</div>

I just tried, this works:

main.lua:

```
network.request("http://localhost/test.php","POST", function( e ) &nbsp; &nbsp; print(e.response) end, { &nbsp; &nbsp; body = "message=hey", })

```

test.php

```
\<?php var\_dump($\_POST); ?\>

```

Prints out:

```
array(1) { &nbsp; &nbsp; ["message"]=\> &nbsp; &nbsp; string(3) "hey" }
```

---

<div class="post-metadata">

**Author:** ![rob](https://forums.solar2d.com/user_avatar/forums.solar2d.com/rob/32/4_2.png) [@rob](https://forums.solar2d.com/u/rob)\
**Post date:** [May 25, 2018, 3:06pm UTC](https://forums.solar2d.com/t/network-request-post-not-sending-data-what-am-i-doing-wrong/347663/3 "2018-05-25T15:06:47Z")

</div>

There is a pretty well known issue with PHP and $\_POST array’s being empty. It’s not a Corona issue, but a PHP and hosting issue.&nbsp; If you Google “PHP $\_POST empty”:

[https://www.google.com/search?q=php+%24\_post+empty&oq=php+%24\_POST](https://www.google.com/search?q=php+%24_post+empty&oq=php+%24_POST)

You will get a bunch of hits about this.

Rob

---

<div class="post-metadata">

**Author:** ![Milner99](https://forums.solar2d.com/user_avatar/forums.solar2d.com/milner99/32/2091_2.png) [@Milner99](https://forums.solar2d.com/u/Milner99)\
**Post date:** [May 25, 2018, 3:07pm UTC](https://forums.solar2d.com/t/network-request-post-not-sending-data-what-am-i-doing-wrong/347663/4 "2018-05-25T15:07:55Z")

</div>

Thanks for coming back Vlad - I’ve sorted it between then and now - turns out it was down to the url form encoding. I needed to change the Content-type to&nbsp;application/x-www-form-urlencoded

---

<div class="post-metadata">

**Author:** ![Milner99](https://forums.solar2d.com/user_avatar/forums.solar2d.com/milner99/32/2091_2.png) [@Milner99](https://forums.solar2d.com/u/Milner99)\
**Post date:** [May 25, 2018, 3:09pm UTC](https://forums.solar2d.com/t/network-request-post-not-sending-data-what-am-i-doing-wrong/347663/5 "2018-05-25T15:09:31Z")

</div>

> [@rob](#):
>
> There is a pretty well known issue with PHP and $\_POST array’s being empty. It’s not a Corona issue, but a PHP and hosting issue.&nbsp; If you Google “PHP $\_POST empty”:
> 
> [https://www.google.com/search?q=php+%24\_post+empty&oq=php+%24\_POST](https://www.google.com/search?q=php+%24_post+empty&oq=php+%24_POST)
> 
> You will get a bunch of hits about this.
> 
> Rob

Agreed Rob (obviously).

Ended up using the PHP:

```
$sets = explode('&', file\_get\_contents('php://input')); for($i=0;$i\<count($sets); $i++) { $keyval = explode('=', $sets[$i]); echo $keyval[0] . " ==== " . $keyval[1] . " ---- "; }

```

This exploded out both by ‘&’ and then by ‘=’ which helped me to get to the base64 ended image

---

<div class="post-metadata">

**Author:** ![vlads](https://forums.solar2d.com/user_avatar/forums.solar2d.com/vlads/32/29_2.png) [@vlads](https://forums.solar2d.com/u/vlads)\
**Post date:** [May 25, 2018, 3:16pm UTC](https://forums.solar2d.com/t/network-request-post-not-sending-data-what-am-i-doing-wrong/347663/6 "2018-05-25T15:16:01Z")

</div>

It was my guess, but I wasn’t sure… I would leave content type haeader to corona to figure out.

---

<div class="post-metadata">

**Author:** ![vlads](https://forums.solar2d.com/user_avatar/forums.solar2d.com/vlads/32/29_2.png) [@vlads](https://forums.solar2d.com/u/vlads)\
**Post date:** [May 25, 2018, 2:59pm UTC](https://forums.solar2d.com/t/network-request-post-not-sending-data-what-am-i-doing-wrong/347663/7 "2018-05-25T14:59:47Z")

</div>

I just tried, this works:

main.lua:

```
network.request("http://localhost/test.php","POST", function( e ) &nbsp; &nbsp; print(e.response) end, { &nbsp; &nbsp; body = "message=hey", })

```

test.php

```
\<?php var\_dump($\_POST); ?\>

```

Prints out:

```
array(1) { &nbsp; &nbsp; ["message"]=\> &nbsp; &nbsp; string(3) "hey" }
```

---

<div class="post-metadata">

**Author:** ![rob](https://forums.solar2d.com/user_avatar/forums.solar2d.com/rob/32/4_2.png) [@rob](https://forums.solar2d.com/u/rob)\
**Post date:** [May 25, 2018, 3:06pm UTC](https://forums.solar2d.com/t/network-request-post-not-sending-data-what-am-i-doing-wrong/347663/8 "2018-05-25T15:06:47Z")

</div>

There is a pretty well known issue with PHP and $\_POST array’s being empty. It’s not a Corona issue, but a PHP and hosting issue.&nbsp; If you Google “PHP $\_POST empty”:

[https://www.google.com/search?q=php+%24\_post+empty&oq=php+%24\_POST](https://www.google.com/search?q=php+%24_post+empty&oq=php+%24_POST)

You will get a bunch of hits about this.

Rob

---

<div class="post-metadata">

**Author:** ![Milner99](https://forums.solar2d.com/user_avatar/forums.solar2d.com/milner99/32/2091_2.png) [@Milner99](https://forums.solar2d.com/u/Milner99)\
**Post date:** [May 25, 2018, 3:07pm UTC](https://forums.solar2d.com/t/network-request-post-not-sending-data-what-am-i-doing-wrong/347663/9 "2018-05-25T15:07:55Z")

</div>

Thanks for coming back Vlad - I’ve sorted it between then and now - turns out it was down to the url form encoding. I needed to change the Content-type to&nbsp;application/x-www-form-urlencoded

---

<div class="post-metadata">

**Author:** ![Milner99](https://forums.solar2d.com/user_avatar/forums.solar2d.com/milner99/32/2091_2.png) [@Milner99](https://forums.solar2d.com/u/Milner99)\
**Post date:** [May 25, 2018, 3:09pm UTC](https://forums.solar2d.com/t/network-request-post-not-sending-data-what-am-i-doing-wrong/347663/10 "2018-05-25T15:09:31Z")

</div>

> [@rob](#):
>
> There is a pretty well known issue with PHP and $\_POST array’s being empty. It’s not a Corona issue, but a PHP and hosting issue.&nbsp; If you Google “PHP $\_POST empty”:
> 
> [https://www.google.com/search?q=php+%24\_post+empty&oq=php+%24\_POST](https://www.google.com/search?q=php+%24_post+empty&oq=php+%24_POST)
> 
> You will get a bunch of hits about this.
> 
> Rob

Agreed Rob (obviously).

Ended up using the PHP:

```
$sets = explode('&', file\_get\_contents('php://input')); for($i=0;$i\<count($sets); $i++) { $keyval = explode('=', $sets[$i]); echo $keyval[0] . " ==== " . $keyval[1] . " ---- "; }

```

This exploded out both by ‘&’ and then by ‘=’ which helped me to get to the base64 ended image

---

<div class="post-metadata">

**Author:** ![vlads](https://forums.solar2d.com/user_avatar/forums.solar2d.com/vlads/32/29_2.png) [@vlads](https://forums.solar2d.com/u/vlads)\
**Post date:** [May 25, 2018, 3:16pm UTC](https://forums.solar2d.com/t/network-request-post-not-sending-data-what-am-i-doing-wrong/347663/11 "2018-05-25T15:16:01Z")

</div>

It was my guess, but I wasn’t sure… I would leave content type haeader to corona to figure out.
