network.request PUT and MacOS Simulator

I have an application that interfaces to a custom REST server.  The application can GET, POST, PUT, and DELETE fine on Android.  On MacOS, iOS, GETs are working fine and POST and PUT without a body work fine, but when i try a PUT with json.encode table in the params, the data does not make it through the server.

 \_userInfo.profile = deepcopy(userProfile) \_userInfo.segments = deepcopy(userSegments) \_userInfo.deviceIds = deepcopy(userDeviceIds) \_userInfo.deviceModels = deepcopy(userDeviceModels) print('mbapi:saveUser '..userid) print('userInfo:: '..json.encode(\_userInfo)) local url = \_url['user']..'/'..userid network.request(url, "PUT", function(e) if e.isError then end end, netReqParams(jwt,\_userInfo,\_userInfo) )

where netReqParams is 

local function netReqParams(jwt,data,body) -- WINDOWS ANDROID SIMULATOR - OK -- ANDROID DEVICE - OK -- MAC EMULATOR - -- MAC SIMULATOR - -- IOS DEVICE - local params = {} local headers = {} headers["Content-Type"] = "application/json"--; charset=utf-8" headers["Authorization"] = jwt params.headers = headers if data ~= {} then params.data = json.encode(data) end if body ~= {} then params.body = json.encode(body) end params.timeout = 0.010 return params end

any thoughts on why this works with Windows and Android, but not MacOS and iOS.  The server is HTTPS with TLS1.2.

What errors are you getting? I’m having a similar issue. Here’s the output from my device - tidied up a little:

App[59150] \<Notice\>: Uploading&nbsp; test.zip App(CFNetwork)[59150] \<Notice\>: TIC Enabling TLS [4:0x1c017efc0] App(CFNetwork)[59150] \<Notice\>: TIC TCP Conn Start [4:0x1c017efc0] App(CFNetwork)[59150] \<Notice\>: Task \<28D00051-A78C-44F7-8524-73F547796FD7\>.\<0\> setting up Connection 4 App(CFNetwork)[59150] \<Notice\>: TIC TLS Event [4:0x1c017efc0]: 1, Pending(0) App(CFNetwork)[59150] \<Notice\>: TIC TLS Event [4:0x1c017efc0]: 2, Pending(0) App(CFNetwork)[59150] \<Notice\>: TIC TLS Event [4:0x1c017efc0]: 11, Pending(0) App(CFNetwork)[59150] \<Notice\>: TIC TLS Event [4:0x1c017efc0]: 12, Pending(0) App(CFNetwork)[59150] \<Notice\>: TIC TLS Event [4:0x1c017efc0]: 14, Pending(0) App(CFNetwork)[59150] \<Notice\>: System Trust Evaluation yielded status(0) App(CFNetwork)[59150] \<Notice\>: TIC TLS Trust Result [4:0x1c017efc0]: 0 App(CFNetwork)[59150] \<Notice\>: TIC TLS Event [4:0x1c017efc0]: 20, Pending(0) App(CFNetwork)[59150] \<Notice\>: TIC TCP Conn Connected [4:0x1c017efc0]: Err(16) App(CFNetwork)[59150] \<Notice\>: TIC TCP Conn Event [4:0x1c017efc0]: 1 App(CFNetwork)[59150] \<Notice\>: TIC TCP Conn Event [4:0x1c017efc0]: 8 App(CFNetwork)[59150] \<Notice\>: TIC TLS Handshake Complete [4:0x1c017efc0] App(CFNetwork)[59150] \<Notice\>: Task \<28D00051-A78C-44F7-8524-73F547796FD7\>.\<0\> now using Connection 4 App(CFNetwork)[59150] \<Notice\>: Task \<28D00051-A78C-44F7-8524-73F547796FD7\>.\<0\> sent request, body S App(CFNetwork)[59150] \<Notice\>: Task \<28D00051-A78C-44F7-8524-73F547796FD7\>.\<0\> received response, status 401 content K App(CFNetwork)[59150] \<Error\>: CredStore - performQuery - Error copying matching creds.&nbsp; Error=-25300, query=\<private\> App(CFNetwork)[59150] \<Error\>: NSURLConnection finished with error - code -1021 App[59150] \<Notice\>: ERROR: network: network request failed: URL [-1021: request body stream exhausted] App[59150] \<Notice\>: Upload error request body stream exhausted App[59150] \<Notice\>: Completed&nbsp; test.zip&nbsp; -1 App(CFNetwork)[59150] \<Notice\>: TIC TCP Conn Event [4:0x1c017efc0]: 2 App(CFNetwork)[59150] \<Notice\>: TIC TCP Conn Cancel [4:0x1c017efc0] &nbsp; &nbsp;

Note I’m uploading a zip as opposed to a string. 

tap32,

it has been a while since this issue arose and i didn’t root cause it… my issue was restricted to tables embedded in tables.  They did not make it across the network request (whether corona or server-side i don’t know at the moment) without getting perturbed.  my resolution was to flatten the data structure…and/or provide accesses over REST to substructures that were flat.  At least, that’s how i recall it at the moment.  and rereading my post now i can see why there was no response… i provided no information on what the failure observation was.

alg

I did a search on “-1021: request body stream exhausted” 

https://www.google.com/search?q=-1021%3A+request+body+stream+exhausted&oq=-1021%3A+request+body+stream+exhausted&aqs=chrome…69i57.477j0j7&sourceid=chrome&ie=UTF-8

And there are bunches of results over several years, many different platforms and more, so this doesn’t seem like it’s a likely Corona issue.  I didn’t see any common issues, other than a couple of people suggesting that the credentials being sent don’t match what the server is expecting.  Other common threads were networking related and the problem cleared up or some bandwidth was exceeded.

Maybe reading over some of those links might resonate with your specific use.

Rob

Thanks, I did some searching and came across a bug on AFNetworking which suggested the issue was iOS specific triggered by a multipart post with an authentication challenge. I have no idea how related that bug and my issue are, but they suggested switching from URL authentication to including the authentication in headers. I also noticed a MDN page on basic authentication which suggested that the URL format had been deprecated. With both of these in mind I switched to using the following headers:

local headers = {} &nbsp; headers["Content-Type"] = "application/zip" &nbsp; headers["Authorization"] = "Basic " ..encodeAuthorization() &nbsp; local params = {} &nbsp; params.headers = headers &nbsp; &nbsp; params.body = { &nbsp; &nbsp; &nbsp; filename = filename, &nbsp; &nbsp; &nbsp; baseDirectory = baseDirectory&nbsp; &nbsp; } &nbsp; print ('Uploading',filename) &nbsp; network.request(path..filename, "PUT", handleResponse, params)

function encodeAuthorization() &nbsp; return mime.b64(("%s:%s"):format(username,password)) end &nbsp;

Now it seems to work. However without knowing for sure, I am now trying to get my hands on the server logs so I can confirm. 

What errors are you getting? I’m having a similar issue. Here’s the output from my device - tidied up a little:

App[59150] \<Notice\>: Uploading&nbsp; test.zip App(CFNetwork)[59150] \<Notice\>: TIC Enabling TLS [4:0x1c017efc0] App(CFNetwork)[59150] \<Notice\>: TIC TCP Conn Start [4:0x1c017efc0] App(CFNetwork)[59150] \<Notice\>: Task \<28D00051-A78C-44F7-8524-73F547796FD7\>.\<0\> setting up Connection 4 App(CFNetwork)[59150] \<Notice\>: TIC TLS Event [4:0x1c017efc0]: 1, Pending(0) App(CFNetwork)[59150] \<Notice\>: TIC TLS Event [4:0x1c017efc0]: 2, Pending(0) App(CFNetwork)[59150] \<Notice\>: TIC TLS Event [4:0x1c017efc0]: 11, Pending(0) App(CFNetwork)[59150] \<Notice\>: TIC TLS Event [4:0x1c017efc0]: 12, Pending(0) App(CFNetwork)[59150] \<Notice\>: TIC TLS Event [4:0x1c017efc0]: 14, Pending(0) App(CFNetwork)[59150] \<Notice\>: System Trust Evaluation yielded status(0) App(CFNetwork)[59150] \<Notice\>: TIC TLS Trust Result [4:0x1c017efc0]: 0 App(CFNetwork)[59150] \<Notice\>: TIC TLS Event [4:0x1c017efc0]: 20, Pending(0) App(CFNetwork)[59150] \<Notice\>: TIC TCP Conn Connected [4:0x1c017efc0]: Err(16) App(CFNetwork)[59150] \<Notice\>: TIC TCP Conn Event [4:0x1c017efc0]: 1 App(CFNetwork)[59150] \<Notice\>: TIC TCP Conn Event [4:0x1c017efc0]: 8 App(CFNetwork)[59150] \<Notice\>: TIC TLS Handshake Complete [4:0x1c017efc0] App(CFNetwork)[59150] \<Notice\>: Task \<28D00051-A78C-44F7-8524-73F547796FD7\>.\<0\> now using Connection 4 App(CFNetwork)[59150] \<Notice\>: Task \<28D00051-A78C-44F7-8524-73F547796FD7\>.\<0\> sent request, body S App(CFNetwork)[59150] \<Notice\>: Task \<28D00051-A78C-44F7-8524-73F547796FD7\>.\<0\> received response, status 401 content K App(CFNetwork)[59150] \<Error\>: CredStore - performQuery - Error copying matching creds.&nbsp; Error=-25300, query=\<private\> App(CFNetwork)[59150] \<Error\>: NSURLConnection finished with error - code -1021 App[59150] \<Notice\>: ERROR: network: network request failed: URL [-1021: request body stream exhausted] App[59150] \<Notice\>: Upload error request body stream exhausted App[59150] \<Notice\>: Completed&nbsp; test.zip&nbsp; -1 App(CFNetwork)[59150] \<Notice\>: TIC TCP Conn Event [4:0x1c017efc0]: 2 App(CFNetwork)[59150] \<Notice\>: TIC TCP Conn Cancel [4:0x1c017efc0] &nbsp; &nbsp;

Note I’m uploading a zip as opposed to a string. 

tap32,

it has been a while since this issue arose and i didn’t root cause it… my issue was restricted to tables embedded in tables.  They did not make it across the network request (whether corona or server-side i don’t know at the moment) without getting perturbed.  my resolution was to flatten the data structure…and/or provide accesses over REST to substructures that were flat.  At least, that’s how i recall it at the moment.  and rereading my post now i can see why there was no response… i provided no information on what the failure observation was.

alg

I did a search on “-1021: request body stream exhausted” 

https://www.google.com/search?q=-1021%3A+request+body+stream+exhausted&oq=-1021%3A+request+body+stream+exhausted&aqs=chrome…69i57.477j0j7&sourceid=chrome&ie=UTF-8

And there are bunches of results over several years, many different platforms and more, so this doesn’t seem like it’s a likely Corona issue.  I didn’t see any common issues, other than a couple of people suggesting that the credentials being sent don’t match what the server is expecting.  Other common threads were networking related and the problem cleared up or some bandwidth was exceeded.

Maybe reading over some of those links might resonate with your specific use.

Rob

Thanks, I did some searching and came across a bug on AFNetworking which suggested the issue was iOS specific triggered by a multipart post with an authentication challenge. I have no idea how related that bug and my issue are, but they suggested switching from URL authentication to including the authentication in headers. I also noticed a MDN page on basic authentication which suggested that the URL format had been deprecated. With both of these in mind I switched to using the following headers:

local headers = {} &nbsp; headers["Content-Type"] = "application/zip" &nbsp; headers["Authorization"] = "Basic " ..encodeAuthorization() &nbsp; local params = {} &nbsp; params.headers = headers &nbsp; &nbsp; params.body = { &nbsp; &nbsp; &nbsp; filename = filename, &nbsp; &nbsp; &nbsp; baseDirectory = baseDirectory&nbsp; &nbsp; } &nbsp; print ('Uploading',filename) &nbsp; network.request(path..filename, "PUT", handleResponse, params)

function encodeAuthorization() &nbsp; return mime.b64(("%s:%s"):format(username,password)) end &nbsp;

Now it seems to work. However without knowing for sure, I am now trying to get my hands on the server logs so I can confirm.