# How can I read a value from a file accessed via the Internet?

I have made text file and I put it on Dropbox, I have in this text file a value. From my code, I want to check if this value is 1.

I have tried this code, inspired by the Unity example, but it looks like I'm not able to reach the file.

void Start()
{
StartCoroutine(GetText());
}

IEnumerator GetText()
{

UnityWebRequest www = UnityWebRequest.Get("https://www.dropbox.com/s/6jkhtnpskzsi5pj/TestTXT.txt?dl=0");
yield return www.SendWebRequest();

if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
}
else
{
// Show results as text
// Or retrieve results as binary data
}
}


im not sure about dropBox but requesting from A server of cloud from an app is different from browsers as you dont have sessions and cookies for app requests. certainly you need some authentication headers. try to send a request. if you receive 4XX specially 403 it means you need authentication.

• Is there a better cloud ؟ – NADER LABBAD Sep 9 '19 at 17:14
• @NADERLABBAD if you want to read a file in server side you have to have a serverside login to open the file at serverside and send you its contents. i dont know there is a server or cloud that can give you this. – virtouso Sep 9 '19 at 17:17
• In fact I have succeeded it is A private folder must be public – NADER LABBAD Sep 9 '19 at 17:28

It looks like Unity was not able to download the file. To fix this, I set the dl=1 in the Dropbox URL, instead of dl=0.

Here is the code that made it work for me:

public class DMROnline : MonoBehaviour
{
public string Active;
public string Disable;

public TextAsset textFile;
void Start()
{
StartCoroutine(GetText());
}

IEnumerator GetText()
{
yield return www.SendWebRequest();

if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
}
else
{
// Show results as text