I am trying to upload a file to a vanilla Apache Webserver (v2.4.18) using UnityWebRequest and its Put(uri, bodyData)-Method. The server uses HTTPS and an authentication via username and password. Here’s the code I use:
string url = "https://" + username + ":" + password + "@" + serverUrl + "/" + filename;
byte[] myData = Encoding.UTF8.GetBytes(csvString);
UnityWebRequest www = UnityWebRequest.Put(url, myData);
yield return www.Send();
// and some debugging errors etc. after that
In the editor this works just fine and the file is uploaded correctly, but on iOS it just doesn’t work.
What’s weird is that both in the editor and on iOS the yield seems to never finish, so I don’t get to the debugging code on either platform. When i put the debugging into the Update-Method www.isError is false, but the response stays empty.
A colleague reported that he got NSURLConnection error code -1002, which is a NSURLErrorUnsupportedURL error. Because of this I tried to percent escape the password and filename, because they include characters like : and =, but to no avail. I also tried setting NSAppTransportSecurity → NSAllowsArbitraryLoads to true in the Info.plist, but this doesn’t help either.
Do I need to configure the app or the server somehow? Why does this work in the editor but not on iOS?
I tried the AbsoluteUri property and the url is the same as before and is valid.
The above posted code is all there is to it, I’m trying to Debug.Log(“after request”); right after the yield return www.Send(); but it is never reached. (not allowed to post the username, password or serverUrl, but the filename is just “testios.csv” and the password contains an “=” if that’s important, otherwise there are no special characters used)
I crossposted this issue on Unity Answers (UnityWebRequest.Put fails on iOS - Questions & Answers - Unity Discussions) and tried the answer provided there, but the result is the same. It works perfectly fine in the editor and on Android (except for the endless yield, but the file is uploaded), but not on iOS.
I posted that a colleague gets a NSURLConnection error code -1002, but I don’t get anything when building from Xcode, no matter if I use the code posted above or the one from Unity Answers. Is there anything special I need to do to receive such error codes? At the moment I’m just running the app from Xcode on my device.
Btw I’m using Unity 5.6.0f3, maybe this is due to some bug fixed in a later version?
I finally got it to work. The reason it did not work before was also the reason for the endless yield of the www.Send(); I made a mistake in the callchain of the coroutine. Not exactly sure what was wrong, because I was just calling the coroutine through another coroutine which was started but did not yield the result, but hey, it works now. Thanks a lot for your answer and the help!
Hey, hi, I have the same problem, android and PC are running fine, but the code that was returned by UnityWebRequest request on iOS real machine has been Code: -1002, please help me.
Here’s a sample of my code