Question about network.request and urls

I’m having an issue using POST with a string that points to a file with a space in its name like: myfile (5).txt

I can use network.request with a GET to get this file so I am guessing the function is reformatting the string. However when I try to do a POST request I get a malformed string error.

So my question is, does network.request reformat the string? Is the malformed url coming from your function or iOS?

I read your post twice and can’t really grasp what your problem is. However, since I can see that the error involves URLs and whitespaces, I will go for a wild guess: Is the filename part of an URL? If yes, are you encoding your URL correctly? E.g. using socket.url.escape() or some other method of URL encoding?

All URL’s need to be properly encoded before transmitting.  Spaces need to be turned to +'s or %20’s.  There are several lua based versions of urlencode that you can grab with a simple google search.  Only the values passed to keys need to be encoded

url = “http://somesite.com/some/path?var1=” … urlencode(“some value”) … “&var2=” … urlencode(“some other value”)

But that’s a GET type string.  For POST all of the key-values are put into a variable and passed with the post call, so you would do something like:

body = “var1=” … urlencode(“some value”) … “&var2=” … urlencode(“some other value”)

Rob

Thank you, that helped.

I read your post twice and can’t really grasp what your problem is. However, since I can see that the error involves URLs and whitespaces, I will go for a wild guess: Is the filename part of an URL? If yes, are you encoding your URL correctly? E.g. using socket.url.escape() or some other method of URL encoding?

All URL’s need to be properly encoded before transmitting.  Spaces need to be turned to +'s or %20’s.  There are several lua based versions of urlencode that you can grab with a simple google search.  Only the values passed to keys need to be encoded

url = “http://somesite.com/some/path?var1=” … urlencode(“some value”) … “&var2=” … urlencode(“some other value”)

But that’s a GET type string.  For POST all of the key-values are put into a variable and passed with the post call, so you would do something like:

body = “var1=” … urlencode(“some value”) … “&var2=” … urlencode(“some other value”)

Rob

Thank you, that helped.