1

so all of a sudden I'm getting this error in my unity project.

InvalidOperationException: HTTP/1.1 403 Forbidden
    UnityEngine.Networking.DownloadHandler.GetCheckedDownloader[T] (UnityEngine.Networking.UnityWebRequest www) (at /Users/bokken/buildslave/unity/build/Modules/UnityWebRequest/Public/DownloadHandler/DownloadHandler.bindings.cs:145)
    UnityEngine.Networking.DownloadHandlerAssetBundle.GetContent (UnityEngine.Networking.UnityWebRequest www) (at /Users/bokken/buildslave/unity/build/Modules/UnityWebRequestAssetBundle/Public/DownloadHandlerAssetBundle.bindings.cs:64)
    API+<GetDisplayBundleRoutine>d__5.MoveNext () (at /Users/remy/Unity/AREA/Assets/Scripts/API.cs:58)
    UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/Coroutines.cs:17)

I'm using my own website/server to request an asset bundle. I believe I recently updated the php version to 7.4 of the webserver. Could that be part of the problem? No sure if that is related.

Underneath the script which I use to sort the asset bundles from the server within the app. Not sure if that is related to my current problem though.

I'm requesting bundle in my app via this php-script om the server. 
 // The tab key will cycle through the settings when first created
    // Visit https://codexns.io/products/sftp_for_subime/settings for help
    
    // sftp, ftp or ftps
    "type": "sftp",

    "save_before_upload": true,
    "upload_on_save": false,
    "sync_down_on_open": false,
    "sync_skip_deletes": false,
    "sync_same_age": true,
    "confirm_downloads": false,
    "confirm_sync": true,
    "confirm_overwrite_newer": false,
    
    "host": "ssh.strato.com",
    "user": "******",
    "password": "******",
    "port": "22",
    
    "remote_path": "/",
    "ignore_regexes": [
        "\\.sublime-(project|workspace)", "sftp-config(-alt\\d?)?\\.json",
        "sftp-settings\\.json", "/venv/", "\\.svn/", "\\.hg/", "\\.git/",
        "\\.bzr", "_darcs", "CVS", "\\.DS_Store", "Thumbs\\.db", "desktop\\.ini"
    ],
    //"file_permissions": "664",
    //"dir_permissions": "775",
    
    //"extra_list_connections": 0,

    "connect_timeout": 30,
    //"keepalive": 120,
    //"ftp_passive_mode": true,
    //"ftp_obey_passive_host": false,
    //"ssh_key_file": "~/.ssh/id_rsa",
    //"sftp_flags": ["-F", "/path/to/ssh_config"],
    
    //"preserve_modification_times": false,
    //"remote_time_offset_in_hours": 0,
    //"remote_encoding": "utf-8",
    //"remote_locale": "C",
    //"allow_config_upload": false,
}

This is the script I use for api access:

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Networking;

public class API : MonoBehaviour {

    const string BundleFolder = "https://www.remykonings.nl/AssetBundles/";
    const string ItemList = "https://www.remykonings.nl/ItemList.php";

    public void GetItemList(UnityAction<List<string>> callback) {
        StartCoroutine(GetItemListRoutine(callback));
    }

    IEnumerator GetItemListRoutine(UnityAction<List<string>> callback) {
        UnityWebRequest www = UnityWebRequest.Get(ItemList);
        yield return www.SendWebRequest();

        if (www.result == UnityWebRequest.Result.ConnectionError) {
            Debug.Log("Network error");
        } else {
            string rawText = www.downloadHandler.text;
            //split string by comma
            string[] items = rawText.Split(',');
            //remove empty values and convert to list
            List<string> itemList = items.Where(x => !string.IsNullOrEmpty(x)).ToList();
            //return list to caller
            callback.Invoke(itemList);
        }
    }

    public void GetBundleObject(string assetName, UnityAction<GameObject> callback, Transform bundleParent) {
        StartCoroutine(GetDisplayBundleRoutine(assetName, callback, bundleParent));
    }

    IEnumerator GetDisplayBundleRoutine(string assetName, UnityAction<GameObject> callback, Transform bundleParent) {

        string bundleURL = BundleFolder + assetName + "-";

        //append platform to asset bundle name
#if UNITY_ANDROID
        bundleURL += "Android";
#else
        bundleURL += "IOS";
#endif

        Debug.Log("Requesting bundle at " + bundleURL);

        //request asset bundle
        UnityWebRequest www = UnityWebRequestAssetBundle.GetAssetBundle(bundleURL);
        yield return www.SendWebRequest();

        if (www.result == UnityWebRequest.Result.ConnectionError) {
            Debug.Log("Network error");
        } else {
            AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(www);
            if (bundle != null) {
                string rootAssetPath = bundle.GetAllAssetNames()[0];
                GameObject arObject = Instantiate(bundle.LoadAsset(rootAssetPath) as GameObject,bundleParent);
                bundle.Unload(false);
                callback(arObject);
            } else {
                Debug.Log("Not a valid asset bundle");
            }
        }
    }
}

I'm fairly new at all of this. Hoping for some help :)

Thank you.

Remy Konings
  • 35
  • 1
  • 9
  • Have you tried to perform this operation via something like [Postman](https://www.postman.com/), just to see if everything is OK!!!! Are you sure no authentication-related header use to go with the request? – nIcE cOw Aug 29 '21 at 12:58
  • I'm fairly new to programming so there is a good change I'm not understanding all of it. If the request is of https, it requires a authentication-related header? (not sure what a header is in this regard tbh.) It could be that the server moved to https recently yes. – Remy Konings Aug 29 '21 at 13:17
  • No no, `https` shouldn't be any issue, the error state `403-forbidden`, so it mostly relates to authorization. Some `Bearer-token` that needs to be send with the request, that you are missing might can be the case. Let me try it with postman and see I can get some idea. – nIcE cOw Aug 29 '21 at 14:20
  • I tried to make a request to `https://www.remykonings.nl/ItemList.php` and the response received is `keukenmat,`, but the name is suggesting that the response should contain a list, so seems like something is wrong in the `ItemList.php` file while sending response, as can be seen in this [request postman image output](https://imgur.com/a/iZ02Ub8) – nIcE cOw Aug 29 '21 at 14:36
  • 1
    [Response of AssetBundle link](https://imgur.com/a/JOJCp3C). Seems like the permission for the file are not properly set on the server for it to be downloaded or accessed from outside. – nIcE cOw Aug 29 '21 at 15:01
  • Thank you for checking it out via Postman. The list is correct as currently there is only one item on there. – Remy Konings Aug 29 '21 at 15:08
  • You're MOST WELCOME and KEEP SMILING :-) But I was hoping for some sort of a JSON object in its place, and the comma `,` at the end of the string seems dubious to me :-) Please do check the permissions of the AssetBundle file, that might can be the issue. – nIcE cOw Aug 29 '21 at 15:10
  • I'm wondering about the kind of permissions the files needs then. Besides the fact that the php version of the server has changed and it's https now, there is nothing that I have changed to is. Could you explain me perhaps how I can set these permissions on the server? – Remy Konings Aug 29 '21 at 15:11
  • oh, im currently keeping the asset bundles in a google drive folder and I upload it from there. Could this be the problem? I've believe this could mean that certain permission might the affected? – Remy Konings Aug 29 '21 at 15:14
  • 1
    Oke so, that was indeed the problem. Permissions of file can sometimes changes when they're saved in a virtual drive. I've upload the asset bundles from outside the Google Drive folder and requested the bundle from the app again. IT WORKED! Thank you for helping me :) I appreciate your guidance and advice. That made me search in the right direction :) – Remy Konings Aug 29 '21 at 15:20
  • Sorry couldn't see the messages as it was night time so went to sleep :-) But glad you made it through and sorted things out :-) For the rest, You're MOST WELCOME and KEEP SMILING :-) – nIcE cOw Aug 30 '21 at 02:38

0 Answers0