CORS را برای سرورهای VAST پیکربندی کنید
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
مرورگرهای مدرن محدودیتهای امنیتی یکسانی را برای درخواستهای شبکه جاوا اسکریپت اعمال میکنند، به این معنی که یک برنامه وب که از یک مبدأ اجرا میشود نمیتواند دادههای ارائهشده از منبع دیگری را بازیابی کند. برای VAST، این محدودیت امنیتی از خواندن یک پاسخ تبلیغ VAST که از مبدأ متفاوتی ارائه میشود، مانع از خواندن JavaScript XMLHttpRequests ساخته شده از کد رندر VAST در جاوا اسکریپت میشود.
این محدودیت امنیتی برای جلوگیری از مشکلاتی است که در آن یک منبع قادر به خواندن دادههایی از مبدا دیگری است که کاربر ممکن است بدون اجازه آن کاربر به آن وارد شود. این محدودیت مشکلاتی را برای VAST ارائه شده در محیط جاوا اسکریپت ایجاد می کند زیرا سرور تبلیغات اغلب در دامنه متفاوتی نسبت به پخش کننده تبلیغات قرار دارد. با این حال، سرصفحههای اشتراکگذاری منابع متقاطع (CORS) یک توصیه W3C است که با اجازه دادن به اشتراکگذاری در مبادی مختلف، این محدودیت را برطرف میکند.
سرصفحه های CORS
برای جلوگیری از مشکلات مبدأ متقاطع، پاسخهای سرور تبلیغات VAST به درخواستهای ارائه شده توسط SDK باید شامل سرصفحههای HTTP CORS زیر باشد:
Access-Control-Allow-Origin: <origin header value>
Access-Control-Allow-Credentials: true
این هدرها به پخش کننده تبلیغات در هر منبعی اجازه می دهد تا پاسخ VAST را از مبدا سرور آگهی بخواند. مقدار Access-Control-Allow-Origin
روی مقدار سرصفحه Origin
ارسال شده با درخواست تبلیغ و Access-Control-Allow-Credentials
روی true
تنظیم کنید تا مطمئن شوید که کوکی ها به درستی ارسال و دریافت می شوند.
برای دستورالعملهای بیشتر در مورد فعال کردن CORS، به فعال کردن اشتراکگذاری منابع متقاطع مراجعه کنید.
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eModern browsers restrict JavaScript from accessing data from different origins for security reasons, impacting VAST ads served from a separate domain than the player.\u003c/p\u003e\n"],["\u003cp\u003eCross-Origin Resource Sharing (CORS) headers enable cross-origin data sharing, allowing VAST ads to be served from a different domain than the player.\u003c/p\u003e\n"],["\u003cp\u003eVAST ad server responses should include specific CORS headers: \u003ccode\u003eAccess-Control-Allow-Origin\u003c/code\u003e (set to the request's \u003ccode\u003eOrigin\u003c/code\u003e header value) and \u003ccode\u003eAccess-Control-Allow-Credentials\u003c/code\u003e (set to \u003ccode\u003etrue\u003c/code\u003e).\u003c/p\u003e\n"]]],[],null,["# Configure CORS for VAST servers\n\nModern browsers apply same-origin security restrictions to JavaScript network\nrequests, meaning that a web application running from one origin cannot retrieve data\nserved from a different origin. For VAST, this security restriction prevents\nJavaScript XMLHttpRequests made from JavaScript VAST rendering code from reading\na VAST ad response served from a different origin.\n\nThis security restriction is meant to prevent issues where one origin is able\nto read data from another origin that a user may be logged in to without that\nuser's permission. The restriction poses problems for VAST served in a JavaScript\nenvironment because an ad server is often on a different domain than the\nads player. However, [Cross-Origin Resource Sharing (CORS)](//www.w3.org/TR/cors)\nheaders is a W3C recommendation that works around this restriction by allowing\nsharing across different origins.\n\nCORS headers\n------------\n\nTo avoid cross-origin problems, VAST ad server responses to requests made by the SDK must\ninclude following HTTP CORS headers: \n\n```text\nAccess-Control-Allow-Origin: \u003corigin header value\u003e\nAccess-Control-Allow-Credentials: true\n```\n\nThese headers allow an ads player on any origin to read the VAST response\nfrom the ad server origin. Set the value of `Access-Control-Allow-Origin`\nto the value of the `Origin` header sent with the ad request, and\n`Access-Control-Allow-Credentials` to `true` to ensure\nthat cookies are sent and received properly.\n\nFor further instructions on enabling CORS, see\n[Enable cross-origin resource sharing](//enable-cors.org/)."]]