我目前遇到一个关于 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).
我尝试加载的资源是一个 XML 文件,使用以下代码:
\n\nfunction 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我的所有资源文件都与我的页面位于同一域中。
\n\n我已经四处寻找与我相关的问题,但大多数都是关于 CORS 的一般问题,以及如何让它发挥作用。但事实上我没有任何 CORS 问题,没有“www”前缀,这似乎不适用于我的问题。
\n\n …我有一个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) 我正在尝试更新我的应用程序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# 中的 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.dll
(msdn参考)
当我尝试使用 VS2019 的快速操作时,我得到“添加对“office 版本 15.0.0.0”的引用”的选项。执行此快速操作将打开引用管理器,但不会添加任何引用。手动搜索“Office”也不会产生任何简单命名为“office”的结果。最接近的是“Microsoft Office 16.0 Object Library”,已被引用。
据我所知,这与函数参数要求的 …
有这个统一教程称为太空射击游戏,由于某种原因,我得到以下错误:
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 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 的新手,正在尝试制作一个非常简单的 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) 在 Unity Shaderlab 着色器中,您可以向编辑器中的材质检查器公开着色器属性。这可以通过将要公开的属性放置在该Properties
部分中来完成,如下所示
Properties
{
_SomeFloat("A Float", float) = 5
}
Run Code Online (Sandbox Code Playgroud)
Unity 在此处的文档中定义了属性列表。
然而,这不包括任何形式的 float2 或 vector2,只是单个Float
或Vector
由 组成xyzw
。
我尝试将属性类型设置为float2
And 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
值的属性属性或抽屉(例如 …
我有以下 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
但是对于编辑器?
从 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
c# ×5
android ×1
android-network-security-config ×1
aspect-ratio ×1
cors ×1
fmod ×1
hlsl ×1
http ×1
httplistener ×1
https ×1
image ×1
ios ×1
javascript ×1
networking ×1
powerpoint ×1
reference ×1
shader ×1
shaderlab ×1
sockets ×1
ssl ×1
sslstream ×1
tls1.2 ×1
web ×1
xcode ×1