Header Fields not Showing up in request

Here is my network request:

 local headers = {} headers["Content-Type"] = "application/x-www-form-urlencoded" headers["Accept"] = "application/json" headers["x\_customHeader"] = "customHeaderValue" local body = "color=red&size=small" local params = {} params.headers = headers params.body = body network.request( hReq, "POST", networkListener, params)

problem is that my headers are not showing up on the server … hitting a node.js server and printing the req.header immediately i get the following:

{ host: 'localhost:3000', 'user-agent': 'Corona%20Simulator/2013.1198 CFNetwork/596.4.3 Darwin/12.4.0 (x86\_64) (MacBookPro8%2C3)', 'content-length': '0', accept: '\*/\*', 'accept-language': 'en-us', 'accept-encoding': 'gzip, deflate', cookie: 'connect.sid=s%3ApvALisxH9UzRIDdmyJwIyyIy.OIQ%2B8UE51TaP3bE42nsujfkFaTUbRF53QP7EocmS37c', connection: 'keep-alive' }

Seems like the headers are being created by the network.request but none of my header values are present when the request gets to the server.

This is an http request and i am using build 1198

Any ideas would be appreciated … at wits end? 

Funny thing is this code used to work back 50-60 builds ago.

Cheers,

m

I changed my test to hit an echo service and can see that Corona seems to be setting up the headers properly.  Must be something in my server code.

sorry for the question.

anyone looking for such a service or information here is the link:

http://stackoverflow.com/questions/5725430/http-test-server-that-accepts-get-post-calls

Cheers,

m

Well this one gets weirder … am using no custom code in NodeJS … just enough to start a web server.

I have compiled NodeJS with some debugging down where it is parsing the header fields.

When i make a request via Curl like this:

curl -v -i -H "Accept: application/json" -H "x\_accesskey: bobAccess" -H "x\_secret: bobSecret" http://localhost:3000/test

then my debug statement prints out the headers that it encounters which look like:

_addHeaderLine: User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8x zlib/1.2.5

_addHeaderLine: Host: localhost:3000

_addHeaderLine: Accept: application/json

_addHeaderLine: x_accesskey: bobAccess

_addHeaderLine: x_secret: bobSecret

All good right … Now if i make a request via Corona like:

local function \_simpleTest(networkListener) local params = {} local headers = {} headers["Content-Type"] = "application/x-www-form-urlencoded" headers["x\_accesskey"] = "bobAccess" headers["x\_secret"] = "bobSecret" headers["Accept"] = "application/json" params.headers = headers network.request( "http://localhost:3000/test", "GET", networkListener, params ) end

then the debug statements in nodeJS yield:

\_addHeaderLine: Host: localhost:3000 \_addHeaderLine: User-Agent: Corona%20Simulator/2013.1198 CFNetwork/596.4.3 Darwin/12.4.0 (x86\_64) (MacBookPro8%2C3) \_addHeaderLine: Accept: \*/\* \_addHeaderLine: Accept-Language: en-us \_addHeaderLine: Accept-Encoding: gzip, deflate \_addHeaderLine: Cookie: connect.sid=s%3Ab02YgV-ErNsC-sFBDPT8WME6.K0IFYx3v4n4Ld6e09N%2BWN7Emc0dsmvg4b5NTLNlDFZg \_addHeaderLine: Connection: keep-alive

None of my header fields are present.

making the same request to http://httpbin.org/headers which echos the headers sent to it returns:

"headers": { "Accept-Encoding": "gzip, deflate", "Accept-Language": "en-us", "Host": "httpbin.org", "Connection": "close", "User-Agent": "Corona%20Simulator/2013.1198 CFNetwork/596.4.3 Darwin/12.4.0 (x86\_64) (MacBookPro8%2C3)", "X-Accesskey": "bobAccess", "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", "X-Secret": "bobSecret", "Accept": "application/json" }

This one is killing me … it certainly does seem that there is something about the corona headers that is different enough that NodeJS is not liking them.

Anyone have a clue?

Cheers,

m

So … for anyone that gets this far in their quest for a solution to this problem …

I was passing nil for the networkListener … apparently when you do this the network.request ignores your params argument even though you had a nil placeholder in the arguments.

So at a min … define your listener as function () end

… sometimes nothing is easy.

Cheers

I changed my test to hit an echo service and can see that Corona seems to be setting up the headers properly.  Must be something in my server code.

sorry for the question.

anyone looking for such a service or information here is the link:

http://stackoverflow.com/questions/5725430/http-test-server-that-accepts-get-post-calls

Cheers,

m

Well this one gets weirder … am using no custom code in NodeJS … just enough to start a web server.

I have compiled NodeJS with some debugging down where it is parsing the header fields.

When i make a request via Curl like this:

curl -v -i -H "Accept: application/json" -H "x\_accesskey: bobAccess" -H "x\_secret: bobSecret" http://localhost:3000/test

then my debug statement prints out the headers that it encounters which look like:

_addHeaderLine: User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8x zlib/1.2.5

_addHeaderLine: Host: localhost:3000

_addHeaderLine: Accept: application/json

_addHeaderLine: x_accesskey: bobAccess

_addHeaderLine: x_secret: bobSecret

All good right … Now if i make a request via Corona like:

local function \_simpleTest(networkListener) local params = {} local headers = {} headers["Content-Type"] = "application/x-www-form-urlencoded" headers["x\_accesskey"] = "bobAccess" headers["x\_secret"] = "bobSecret" headers["Accept"] = "application/json" params.headers = headers network.request( "http://localhost:3000/test", "GET", networkListener, params ) end

then the debug statements in nodeJS yield:

\_addHeaderLine: Host: localhost:3000 \_addHeaderLine: User-Agent: Corona%20Simulator/2013.1198 CFNetwork/596.4.3 Darwin/12.4.0 (x86\_64) (MacBookPro8%2C3) \_addHeaderLine: Accept: \*/\* \_addHeaderLine: Accept-Language: en-us \_addHeaderLine: Accept-Encoding: gzip, deflate \_addHeaderLine: Cookie: connect.sid=s%3Ab02YgV-ErNsC-sFBDPT8WME6.K0IFYx3v4n4Ld6e09N%2BWN7Emc0dsmvg4b5NTLNlDFZg \_addHeaderLine: Connection: keep-alive

None of my header fields are present.

making the same request to http://httpbin.org/headers which echos the headers sent to it returns:

"headers": { "Accept-Encoding": "gzip, deflate", "Accept-Language": "en-us", "Host": "httpbin.org", "Connection": "close", "User-Agent": "Corona%20Simulator/2013.1198 CFNetwork/596.4.3 Darwin/12.4.0 (x86\_64) (MacBookPro8%2C3)", "X-Accesskey": "bobAccess", "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", "X-Secret": "bobSecret", "Accept": "application/json" }

This one is killing me … it certainly does seem that there is something about the corona headers that is different enough that NodeJS is not liking them.

Anyone have a clue?

Cheers,

m

So … for anyone that gets this far in their quest for a solution to this problem …

I was passing nil for the networkListener … apparently when you do this the network.request ignores your params argument even though you had a nil placeholder in the arguments.

So at a min … define your listener as function () end

… sometimes nothing is easy.

Cheers