Problem with network.request and json string

Hi,

I’m posting data to a WCF service written in ASP.Net and have run into a problem when trying to post a json string. It works fine if I post this string into the service when NOT using Corona.

My LUA code is…

local postContents = {}; postContents.userId = 1; postContents.title ="My Title"; postContents.agreedToTerms = 1; local uploadContentsJson = json.encode (postContents); -- Set correct content type local headers = {         ["Content-Type"] = "application/json",         ["Accept-Language"] = "en-US", } params.headers = headers -- And the rest of the params params.body = "uploadContentsJson="..uploadContentsJson; -- json string params.progress = "upload"; params.timeout = 60; -- (seconds) - default is 30 local url = "https://myservice.mydomain.com/services/service.svc/Upload"; requestId = network.request( url, "POST", fileUploadListener,  params);

So…

  • if I remove the content-type from the headers or change it or just remove the headers altogether, then the post reaches the online .Net service but I get a .Net error which says the content type is expected to be XML or Json.

  • when I put that line back in, my fileUploadListener  event listener fires, and reaches its “ENDED” phase, but nothing is returned.

  • if the equivalent json string is submitted to the service using other methods than Corona, the service runs correctly.

Any help much appreciated - I’m at my wits end!

Thanks,

Ian

Okay - me being an idiot. Figured it out.

This line here…

params.body = "uploadContentsJson="..uploadContentsJson;

should have been

params.body = uploadContentsJson;

My original was sending a normal “query string” style string through with the json as the variable. The service was expecting json and wasn’t getting it. My mistake.

Hopefully if anyone else makes the same error this might help them!

Once I have all this working 100% I’ll post the entire thing as it’s pretty useful for sending files and other data securely from your app to a web service.

Thanks and apologies if I wasted anyone’s time.

Ian

Okay - me being an idiot. Figured it out.

This line here…

params.body = "uploadContentsJson="..uploadContentsJson;

should have been

params.body = uploadContentsJson;

My original was sending a normal “query string” style string through with the json as the variable. The service was expecting json and wasn’t getting it. My mistake.

Hopefully if anyone else makes the same error this might help them!

Once I have all this working 100% I’ll post the entire thing as it’s pretty useful for sending files and other data securely from your app to a web service.

Thanks and apologies if I wasted anyone’s time.

Ian