aws-samples / aws-gaming-unity-labs-sample

This repository contains a sample Unity game project that is used by several Self Paced Labs to demonstrate the use of the AWS Mobile SDK for Unity.
Apache License 2.0
11 stars 6 forks source link

InvalidOperationException: Cannot override system-specified headers #1

Open imyoungyang opened 6 years ago

imyoungyang commented 6 years ago

The code can't execute on Unity 2017.2.0f3

This issue is related to this issue: https://github.com/aws/aws-sdk-net/issues/643

The error message is as the following:

InvalidOperationException: Cannot override system-specified headers UnityEngine.Networking.UnityWebRequest.SetRequestHeader (System.String name, System.String value) (at /Users/builduser/buildslave/unity/build/artifacts/generated/common/modules/UnityWebRequest/WebRequestBindings.gen.cs:511) UnityEngine.WWW..ctor (System.String url, System.Byte[] postData, System.Collections.Generic.Dictionary`2 headers) (at /Users/builduser/buildslave/unity/build/Runtime/WebRequestWWW/UWRWWW.cs:62) Amazon.Runtime.Internal.UnityMainThreadDispatcher+d__7.MoveNext () (at E:/JenkinsWorkspaces/v3-stage-release/AWSDotNetPublic/sdk/src/Core/Amazon.Runtime/Pipeline/_unity/UnityMainThreadDispatcher.cs:135) UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at /Users/builduser/buildslave/unity/build/Runtime/Export/Coroutines.cs:17) UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator) Amazon.Runtime.Internal.UnityMainThreadDispatcher:ProcessRequests() (at E:/JenkinsWorkspaces/v3-stage-release/AWSDotNetPublic/sdk/src/Core/Amazon.Runtime/Pipeline/_unity/UnityMainThreadDispatcher.cs:73) Amazon.Runtime.Internal.UnityMainThreadDispatcher:Update() (at E:/JenkinsWorkspaces/v3-stage-release/AWSDotNetPublic/sdk/src/Core/Amazon.Runtime/Pipeline/_unity/UnityMainThreadDispatcher.cs:59)

sapessi commented 6 years ago

I've managed to resolve this by overriding the HTTP client the SDK uses. From the first behavior the application uses, before any call is made to AWS, you can set the AWSConfigs property:

AWSConfigs.HttpClient = AWSConfigs.HttpClientOption.UnityWebRequest;
daveProgramming commented 6 years ago

Where do I put this code?

sapessi commented 6 years ago

@daveProgramming I added this to the first behavior loaded by the game. The AWSConfigs contains static variables so once it's set it should be re-used by all other instances of the SDK.

OverworldOwl commented 6 years ago

Seems to work for me. Thanks!

thedanitime commented 6 years ago

I had that problem too, thanks!

Legogo commented 6 years ago

I added AWSConfigs.HttpClient = AWSConfigs.HttpClientOption.UnityWebRequest; in the Start() function of the S3Example.cs like so

    void Start()
    {
        UnityInitializer.AttachToGameObject(this.gameObject);
        GetBucketListButton.onClick.AddListener(() => { GetBucketList(); });
        PostBucketButton.onClick.AddListener(() => { PostObject(); });
        GetObjectsListButton.onClick.AddListener(() => { GetObjects(); });
        DeleteObjectButton.onClick.AddListener(() => { DeleteObject(); });
        GetObjectButton.onClick.AddListener(() => { GetObject(); });

        AWSConfigs.HttpClient = AWSConfigs.HttpClientOption.UnityWebRequest;
    }

And it seems to work. At least in 2018.1.3 editor.

jlankitus commented 6 years ago

Hey all,

This worked great for me in Windows! However this seems to crash webgl. Anyone have alternatives to this for WebGL or know if its impossible?

chen1013 commented 6 years ago

I'm using the Cognito service. This works for me as well. Thank you sooooo much!

yongyili commented 5 years ago

This also works for me in Mac and I am using the GameLift service. Thanks a lot.

tsogtbayar123 commented 5 years ago

It works after adding Legogo's code in start function. thnx a lot.

jmdjr commented 4 years ago

The line of code speficied doesn't seem to work in the latest version, could be that, at least with the assets in the Chess game example, AWSConfigs does not contain HttpClient

MobileAppsFirst commented 3 years ago

With aws-sdk-unity_3.3.802.0 and Unity 2019.4.18f1 it seems that the solution with HttpClient is not working. Does anyone have an idea how to fix this?