小编Rem*_*_rm的帖子

仅当 url 以 www 为前缀时才会发生 CORS 错误

我目前遇到一个关于 CORS(跨源资源共享)的问题,奇怪的是,只有当我使用 www.url 前缀时,才会出现这种情况。

\n\n

例如,当我使用网址“ http://example.com/index ”访问我的网站时,一切正常并且所有资源都已正确加载。但是,当我尝试使用网址“ http://www.example.com/index ”访问我的网站时,我收到错误Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://example.com/index. (Reason: CORS header \xe2\x80\x98Access-Control-Allow-Origin\xe2\x80\x99 missing).

\n\n

我尝试加载的资源是一个 XML 文件,使用以下代码:

\n\n

\r\n
\r\n
function loadXML()\r\n{\r\n    var xhttp = new XMLHttpRequest();\r\n    xhttp.onreadystatechange = function() {\r\n        if (this.readyState == 4 && this.status == 200) {\r\n            xmlData = xhttp.responseXML;\r\n            initStartShot();\r\n        }\r\n    };\r\n    xhttp.open("GET", "http://example.com/XML/someXMLfile.xml", true);\r\n    xhttp.send();\r\n}
Run Code Online (Sandbox Code Playgroud)\r\n
\r\n
\r\n

\n\n

我的所有资源文件都与我的页面位于同一域中。

\n\n

我已经四处寻找与我相关的问题,但大多数都是关于 CORS 的一般问题,以及如何让它发挥作用。但事实上我没有任何 CORS 问题,没有“www”前缀,这似乎不适用于我的问题。

\n\n …

javascript xmlhttprequest cors web

7
推荐指数
1
解决办法
4556
查看次数

HttpContext.Response底层套接字意外关闭

我有一个HttpListener侦听指定端口上localhost(即192.168.0.10/Foobar.ext)上的任何文件请求(在这种情况下,特别是它是使用.m3u8头文件和.ts视频文件的HLS流.但系统应适用于任何类型的文件).

IAsyncResult result = listener.BeginGetContext(new AsyncCallback(HttpRequestListenerCallback), listener);
result.AsyncWaitHandle.WaitOne(1);
Run Code Online (Sandbox Code Playgroud)

当发出请求时,回调会HttpListenerContext为所请求的文件(仅限该文件)创建一个,并提取如下文件名:

HttpListenerContext context = listener.EndGetContext(result);
string fileName = context.Request.Url.AbsolutePath.Substring(1);
Run Code Online (Sandbox Code Playgroud)

将上下文添加到调用httpContexts并链接到int 的字典中commandSequenceNumber以跟踪请求.

如果文件名有效,则会将请求发送到服务器以下载文件.文件被下载并被放入一个名为的字节数组中totalBufferdata.到这里一切都很完美.

现在我想将请求的(视频)文件的字节数据写回请求文件HttpListenerContext.Response的上下文的response()

为此,我使用以下代码(这文件完全下载发生):

HttpListenerResponse response = httpContexts[commandSequenceNumber].Response; //Get the appropriate context from the dictionary
response.ContentLength64 = totalBufferdata.Count;//set the length response body
Stream responseStream = response.OutputStream; //The stream to which the repsonse needs to be written
try
{
   currentContext.Response.OutputStream.Write(dataNoResponseHeader, 0, dataNoResponseHeader.Length);
}
catch (IOException e)
{ …
Run Code Online (Sandbox Code Playgroud)

c# sockets networking httplistener unity-game-engine

6
推荐指数
1
解决办法
369
查看次数

unity TlsException: 握手失败 UNITYTLS_X509VERIFY_FLAG_NOT_TRUSTED

我正在尝试更新我的应用程序TcpClient以使用 TLSSslStream而不是普通的Stream,我为此使用的代码似乎在 Unity 之外工作,但是当集成到我的 Unity 2019.1.8 中时失败(也在 2018 和 2017 上测试过) ) 项目。

要建立连接并打开一个新连接,SslStream我使用以下代码:

public static void InitClient(string hostName, int port, string certificateName)
{
    client = new TcpClient(hostName, port);

    if (client.Client.Connected)
    {
        Debug.LogFormat("Client connected succesfully");
    }
    else
    {
        Debug.LogErrorFormat("Client couldn't connect");
        return;
    }

    stream = new SslStream(client.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null);

    try
    {
        stream.AuthenticateAsClient(certificateName);
    }
    catch (AuthenticationException e)
    {
        Debug.LogErrorFormat("Error authenticating: {0}", e);
        if (e.InnerException != null)
        {
            Debug.LogErrorFormat("Inner exception: {0}", e); …
Run Code Online (Sandbox Code Playgroud)

c# ssl sslstream unity-game-engine tls1.2

6
推荐指数
1
解决办法
6195
查看次数

PowerPoint.Application.Presentations 缺少 MsoTriState

我正在尝试使用 C# 中的 PowerPoint 来自动化流程,为此我想打开(或创建新的)PowerPoint 演示文稿,添加幻灯片并保存文档。

我已在我的计算机上安装了整个 Office 2019 软件包,并且可以通过引用Interop.Microsoft.Office.Interop.PowerPoint(来自 Microsoft PowerPoint 16.0 对象库参考)以及Interop.Microsoft.Office.Core(来自 Microsoft Office 16.0 对象库参考)来访问 ppt api。

我尝试使用以下代码打开一个powerpoint:

using Microsoft.Office.Interop.PowerPoint;
using Microsoft.Office.Core;

class PowerPointManager
{
    public PowerPointManager()
    {
        string powerPointFileName = @"C:\temp\test.pptx";

        Application pptApplication = new Application();
        Presentation ppt = pptApplication.Presentations.Open(powerPointFileName, MsoTriState.msoTrue); //MsoTriState comes from Microsoft.Office.Core

    }
}

Run Code Online (Sandbox Code Playgroud)

然而,这会导致线路出现错误pptApplication.Presentations.Open

错误 CS0012 类型“MsoTriState”是在未引用的程序集中定义的。您必须添加对程序集“office,Version=15.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c”的引用

即使MsoTriState是最明确定义的,Microsoft.Office.Core它是程序集的一部分office.dllmsdn参考

当我尝试使用 VS2019 的快速操作时,我得到“添加对“office 版本 15.0.0.0”的引用”的选项。执行此快速操作将打开引用管理器,但不会添加任何引用。手动搜索“Office”也不会产生任何简单命名为“office”的结果。最接近的是“Microsoft Office 16.0 Object Library”,已被引用。

据我所知,这与函数参数要求的 …

c# powerpoint reference

6
推荐指数
1
解决办法
1530
查看次数

Unity:您是否缺少程序集引用?

有这个统一教程称为太空射击游戏,由于某种原因,我得到以下错误:

AppData/Local/Unity/cache/packages/packages.unity.com/com.unity.package-manager-ui@2.0.3/Editor/Sources/Services/Upm/UpmBaseOperation.cs(34,43): 
error CS1061: Type 'UnityEditor.PackageManager.PackageInfo' does not contain a definition for 'author' and no extension method 'author' of type 'UnityEditor.PackageManager.PackageInfo' could be found.
Are you missing an assembly reference?
Run Code Online (Sandbox Code Playgroud)

它只是项目的开始,我甚至没有编写任何脚本.我不知道这是什么意思.

unity-game-engine

5
推荐指数
1
解决办法
984
查看次数

无法在 Unity 中的音频源中添加音频剪辑

我在 Unity Scene 中添加了音频源组件,但无法在其中添加音频剪辑。它抛出以下错误:

Errors during import of AudioClip Assets/sound1.ogg:
FSBTool ERROR: The format of the source file is invalid, see output for details.
FSBTool ERROR: Internal error from FMOD sub-system.

UnityEditorInternal.InternalEditorUtility:ProjectWindowDrag(HierarchyProperty, Boolean)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
Run Code Online (Sandbox Code Playgroud)

我正在使用 Unity 版本 2019.3.14f1。我尝试了不同的声源格式(mp3 和 wav),但它产生了相同的错误。如何解决这个问题?

unity-game-engine fmod

5
推荐指数
0
解决办法
1744
查看次数

由于着色器警告和编译器因 XPC_ERROR_CONNECTION_INTERRUPTED 而失败,Unity 应用程序无法在 iOS 上运行

我是 unity 的新手,正在尝试制作一个非常简单的 2D 游戏Xcode。一切似乎都在工作,构建成功。但是,它正在打印以下错误-

2019-10-23 22:27:16.559673-0600 test4[19600:5249871] Built from '2019.2/staging' branch, Version '2019.2.9f1 (ebce4d76e6e8)', Build type 'Release', Scripting Backend 'il2cpp'
    2019-10-23 22:27:16.569618-0600 test4[19600:5249871] -> registered mono modules 0x102e52fd0
    -> applicationDidFinishLaunching()
    2019-10-23 22:27:17.523747-0600 test4[19600:5249871] Metal GPU Frame Capture Enabled
    -> applicationDidBecomeActive()
    GfxDevice: creating device client; threaded=1
    Initializing Metal device caps: Apple A12 GPU
    Initialize engine version: 2019.2.9f1 (ebce4d76e6e8)
    WARNING: Shader Unsupported: 'Hidden/Internal-GUITexture' - Pass '' has no vertex shader
    2019-10-23 22:27:20.289401-0600 test4[19600:5250073] Compiler failed with XPC_ERROR_CONNECTION_INTERRUPTED
    2019-10-23 22:27:20.301490-0600 …
Run Code Online (Sandbox Code Playgroud)

xcode unity-game-engine ios

3
推荐指数
1
解决办法
4284
查看次数

将 float2/vector2 属性从着色器公开到 Unity 材质检查器

在 Unity Shaderlab 着色器中,您可以向编辑器中的材质检查器公开着色器属性。这可以通过将要公开的属性放置在该Properties部分中来完成,如下所示

Properties
{
    _SomeFloat("A Float", float) = 5
}
Run Code Online (Sandbox Code Playgroud)

Unity 在此处的文档中定义了属性列表。

然而,这不包括任何形式的 float2 或 vector2,只是单个FloatVector由 组成xyzw

我尝试将属性类型设置为float2And Vector2

_SomeFloat("A Float", float2) = (5,5)
_SomeFloat2("A Float2", Vector2) = (5,5)
Run Code Online (Sandbox Code Playgroud)

两者都返回错误Parse error: syntax error, unexpected TVAL_ID at line 7

或者试图Vector通过只设置一半的成员来将其减半

_SomeFloat("A Float", Vector) = (5,5)
Run Code Online (Sandbox Code Playgroud)

返回错误Parse error: syntax error, unexpected ')', expecting ','

我可以只使用 Vector 类型并且只使用它的xy,但这会导致 UI 不清晰,因为检查器中现在有两个未使用的元素,并且找不到允许HideInInspector您隐藏zw值的属性属性或抽屉(例如 …

shader hlsl unity-game-engine shaderlab

3
推荐指数
2
解决办法
1万
查看次数

Unity)如何保持精灵的纵横比?

在此输入图像描述

在编辑器中,我的游戏运行良好,但在 Android 设备中,我游戏中的所有图像都会因分辨率而扭曲。

在一些答案中,使用图像组件中的保留方面,但我认为精灵渲染器和图像不能同时使用

我怎么解决这个问题?

c# image aspect-ratio unity-game-engine

3
推荐指数
1
解决办法
6076
查看次数

在编辑器会话之间存储编辑器值

我有以下 EditorWindow 脚本可以创建自定义检查器窗口。在此窗口中按下按钮后,id将增加 1。

static int id = 10000;

[MenuItem("Custom/CustomMenu")]
static void Init()
{
    // Get existing open window or if none, make a new one:
    CustomMenu window = (CustomMenu)EditorWindow.GetWindow(typeof(CustomMenu));
    window.Show();
}

if (GUILayout.Button("someButton"))
{
    id++;
    Repaint();
    EditorUtility.SetDirty(this);
}
Run Code Online (Sandbox Code Playgroud)

这工作正常,但是当我启动播放模式或关闭统一编辑器时,增量值id丢失,并将重置回 10000。

使用 的非静态版本int id将使该值在“播放”会话中持续存在,但一旦关闭 unity 仍会丢失。

有没有办法在编辑器/统一会话之间存储这个值,比如playerprefs但是对于编辑器?

c# unity-game-engine

2
推荐指数
1
解决办法
1348
查看次数

在运行时将network_security_config.xml的域名设置为localhost

从 Android 9 开始,Android 默认情况下仅允许通过 HTTPS 进行网络连接。然而,我正在做的唯一请求是通过本地主机(例如http://10.41.199.226:port/FooBar)完成的,该本地主机由HttpListener侦听该地址:端口组合的(C#)处理。

由于此请求是通过 HTTP 发出的,因此 Android 默认情况下不允许这样做。按照Android 关于该文件的文档,network_security_config我可以通过添加以下network_security_config.xml文件来允许 HTTP 连接

<?xml version="1.0" encoding="utf-8"?>
 <network-security-config>
   <base-config cleartextTrafficPermitted="true">
        <trust-anchors>
            <certificates src="system" />
            <certificates src="user" />
        </trust-anchors>
    </base-config>
    <debug-overrides>
        <trust-anchors>
            <certificates src="user" />
        </trust-anchors>
    </debug-overrides>
</network-security-config>
Run Code Online (Sandbox Code Playgroud)

这是使用 Android 清单调用的android:networkSecurityConfig="@xml/network_security_config"

这允许完成 HTTP 请求,但是因为这设置了基本配置,所以允许在整个应用程序中发出 HTTP 请求。这不是一个好主意,因为我将来可能想添加传出请求,我希望通过 HTTPS 发送请求,并且希望为此建立安全网。让这成为一条不可行的道路。

在同一文档中,他们进一步介绍了domain-config允许您根据域进行设置的功能cleartextTrafficPermitted,我尝试使用以下域集进行设置

<?xml version="1.0" encoding="utf-8"?>
 <network-security-config>
    <domain-config cleartextTrafficPermitted="true">
      <domain includeSubdomains="true">127.0.0.1</domain>
      <domain includeSubdomains="true">10.0.0.1</domain>
      <domain includeSubdomains="true">localhost</domain>
    </domain-config>
</network-security-config>
Run Code Online (Sandbox Code Playgroud)

由于没有结果,请求仍然因不是 https …

https android http android-manifest android-network-security-config

0
推荐指数
1
解决办法
1万
查看次数