Sayfayı Yazdır | Pencereyi Kapat

HTTP access control (CORS)

Nereden Yazdırıldığı: Datakent
Kategori: Diğer bölümler
Forum Adı: C# & ASP.NET
Forum Tanımlaması: C# ve ASP.NET ile ilgili soru / sorun ve paylaşım bölümü
URL: http://forum.datakent.com/forum_posts.asp?TID=2877
Tarih: 28.Mart.2024 Saat 12:03


Konu: HTTP access control (CORS)
Mesajı Yazan: murat turan
Konu: HTTP access control (CORS)
Mesaj Tarihi: 28.Nisan.2016 Saat 14:42
İşlem:
Javascript ile webservis erişiminde karşılaşılabilecek olası hata ver çözümü

Olası Hatalar:

+ Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://82.19.12.146/eta/wsandroid.asmx.
(Reason: CORS header 'Access-Control-Allow-Origin' missing).

+ How to solve the error “SCRIPT7002: XMLHttpRequest: Network Error 0x80070005, Access is denied.” in IE

+ Cross-Origin Request Blocked

+ HTTP access control (CORS)

Çözümü:
Web uygulamanın web.config dosyasını açınız ve aşağıda belirtilen (italik) kısımları dosyaya ekleyiniz. Ayarlamaları kendime göre yaptım zira opsiyonlarda değişiklik yapabilirsiniz. Bu ayarlamalarla webservis'e eriştim ve denemeyi FireFox ve IE de yaptım.

*** Web.config'e eklenecek kısım italiktir  / add to web.config
.........
 </system.web
>
 
 <system.webServer>
   <httpProtocol>
     <customHeaders>
       <add name="Access-Control-Allow-Origin" value="*" />
       <add name="Access-Control-Allow-Headers" value="soapaction, Man, Host, x-requested-with, Content-Type, origin, authorization, accept, client-security-token" />
       <add name="Access-Control-Allow-Methods" value="POST, GET, OPTIONS, DELETE, PUT" />
     </customHeaders>
   </httpProtocol>
 </system.webServer>

 
</configuration>


örnek bir uygulama / soap example:
<!DOCTYPE html>
<head>
    <title>SOAP JavaScript Client Test from by datakent.com</title>
    <script type="text/javascript">

        function soap_dk() {
            var sr =
                '<?xml version="1.0" encoding="utf-8"?>\r\n' +
                '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">\r\n' +
                '  <soap:Body>\r\n' +
                '    <checkLogin xmlns="http://tempuri.org/">\r\n' +
                '      <xp1>aaa</xp1>\r\n' +
                '      <xp2>bbb</xp2>\r\n' +
                '      <xp3>ccc</xp3>\r\n' +
                '    </checkLogin>\r\n' +
                '  </soap:Body>\r\n' +
                '</soap:Envelope>';


            var xmlhttp = new XMLHttpRequest();
            xmlhttp.open('POST', 'http://82.19.12.146/eta/wsandroid.asmx', true);
            xmlhttp.setRequestHeader('Man', 'POST /wsandroid.asmx HTTP/1.1');
            xmlhttp.setRequestHeader('Host', '82.19.12.146');
            xmlhttp.setRequestHeader('Content-Type', 'text/xml;charset=UTF-8');//;
            xmlhttp.setRequestHeader('SOAPAction', 'http://tempuri.org/checkLogin');
            xmlhttp.setRequestHeader('Content-Length', sr.length.toString());

            xmlhttp.onreadystatechange = function () {
                if (xmlhttp.readyState == 4) {
                    if (xmlhttp.status == 200) {
                        alert('Okay. use F12 and look at network response');
                    }
                }
            }

            xmlhttp.send(sr);
        }



    </script>
</head>
<body>
    <form name="test1" action="" method="post">
        <div>
            <input type="button" value="Soap-Test" onclick="soap_dk();" />
        </div>
    </form>
</body>
</html>



-------------
http://www.kasatakip.com - Kasa Takip  |  http://www.caritakip.com - Cari Takip  |  http://www.evraktakip.com - Evrak Takip  |  http://www.etasqlmobil.com - ETA SQL Mobil



Sayfayı Yazdır | Pencereyi Kapat