Home > Net >  C # turn Javascript prompt 'Access - Control - Allow - Origin' header is present on the re
C # turn Javascript prompt 'Access - Control - Allow - Origin' header is present on the re

Time:09-17

 
$(function () {
Var Settings={
"Async" : true,
"CrossDomain" : true,
"Url" : "http://192.168.1.60/ISAPI/System/Video/inputs/channels/1/overlays/text",
"Method" : "PUT",
"Headers" : {
"Access - Control - Allow - Origin" : "*",
"Authorization" : "Basic YWRtaW46enp4eTEyMzQ1Ng==",
"Cache-control" : "no - cache,"
"Postman - Token" : "0 c288f09-09 c6-4088 - b79b - c969b2833124"
},
"Data" : "& lt; TextOverlayList size=\ \ "500 " & gt; 1 True 10 70 & lt;/positionY> Dongfeng 4-1868-11/hour DK200 + 509 & lt;/displayText> "
}

$. Ajax (Settings). The done (function (response) {
Layer. MSG (" & lt; Span style="color: # FFFFFF; '& gt; Has updated! " );
});
});
</script>


Perform on a piece of code hint: (the code above is the following c # transformation, through the POSTman execution is no problem, but in the browser is washed-up, the client can't install IIS server compilation aspx file, how to solve?
http://192.168.1.60/ISAPI/System/Video/inputs/channels/1/overlays/text'Access - Control - Allow - Origin' header is present on the requested resource.

The following c # perform no problem, I need the client JS scripts run successfully, because it is LAN IP,
 

String URI="http://192.168.1.60/ISAPI/System/Video/inputs/channels/1/overlays/text";
The Stream outstream=null;
The Stream instream=null;
StreamReader sr=null;

//the new definition of HTTP request, cannot use the new, https://msdn.microsoft.com/zh-cn/library/system.net.httpwebresponse (v=versus 110). Aspx
HttpWebRequest the req=(HttpWebRequest) WebRequest. Create (URI).
//to note this is the encoding, and the content of the Xml content encoding
Encoding Encoding=Encoding. GetEncoding (" utf-8 ");
Byte [] data=https://bbs.csdn.net/topics/System.Text.Encoding.UTF8.GetBytes (xmlPath);
The req. Method="PUT";
The req. ContentType="text/plain; Charset=utf-8 ";
//add user name password to complete the Authorization certification
String username="admin";
String password="zzxy123456";
String userPasswd=+ ":" username + password;
CredentialCache mycache=new CredentialCache ();
Mycache. Add (new Uri (Uri), the "Basic", new NetworkCredential (username, password));
The req. Credentials=mycache;
The req. Headers. The Add (" Authorization ", "Basic" + Convert. ToBase64String (new ASCIIEncoding () GetBytes (userPasswd)));
//send content
Outstream=the req. GetRequestStream ();
Outstream. Write (data, 0, the data Length);
Outstream. Flush ();
Outstream. Close ();

HttpWebResponse res=(HttpWebResponse) the req. The method GetResponse ();
//receive NVR return data information
Res=the req. The method GetResponse () as HttpWebResponse;
//until the req. The method GetResponse () program to start sending a Post request to the target web page
Instream=res. GetResponseStream ();
The sr=new StreamReader (instream, encoding);
//return the result page code
The string content=sr. ReadToEnd ();
The Console. Write (content);
The Console. The Read ();

CodePudding user response:

"crossDomain" : true,

This, no corresponding translation, after all, she is declared the cross-domain Access your current return is also "' Access - Control - Allow - Origin" cross domain Access failure

So when you submit, please add: to the water head area Access - Control - Allow - Origin mark

CodePudding user response:

So in the HTML head? The head between
<meta HTTP - equiv="Access - Control - Allow - Origin" content="*"/& gt;

 


<meta HTTP - equiv="Access - Control - Allow - Origin" content="*"/& gt;
* * * * * * * * * * * * & lt;/title> <br/><script SRC="https://bbs.csdn.net/TrainDB/Scripts/jquery-1.10.2.min.js" & gt; </script> <br/><script SRC="https://bbs.csdn.net/TrainDB/Scripts/layer/layer.js" & gt; </script> <br/><style> <br/></style> <br/></head> <br/><body> <br/><The form id="aspnetForm" runat="server" & gt; <br/><The script type="text/javascript" & gt; <br/>$(function () {<br/>Var Settings={<br/>"Async" : true, <br/>"CrossDomain" : true, <br/>"Url" : "http://192.168.1.60/ISAPI/System/Video/inputs/channels/1/overlays/text", <br/>"Method" : "PUT", <br/>//"dataType" : "the json," <br/>"Headers" : {<br/>"Access - Control - Allow - Origin" : "*", <br/>"Access - Control - Allow - the Methods" : "POST, GET, PUT," <br/>"Authorization" : "Basic YWRtaW46enp4eTEyMzQ1Ng==", <br/>"Cache-control" : "no - cache," <br/>"Postman - Token" : "0 c288f09-09 c6-4088 - b79b - c969b2833124" <br/>}, <br/>"Data" : "& lt; TextOverlayList size=\ \ "500 " & gt; <TextOverlay> <Id> 1</id> <Enabled> True</enabled> <PositionX> 10</positionX> <PositionY> 70 & lt;/positionY> <DisplayText> Dongfeng 4-1868-11/hour DK200 + 509 & lt;/displayText> </TextOverlay> </TextOverlayList>" <br/>} <br/><br/><br/>$. Ajax (Settings). The done (function (response) {<br/>Layer. MSG (" & lt; Span style="color: # FFFFFF; '& gt; Has updated! </span>" ); <br/>}); <br/><br/></script> <br/></form> <br/></body> <br/></html> <br/><br/></pre> <br/><br/>nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull </div> <div class="th_page th_page_color"></div> <div class="umCopyright"> <p>Page link:<a href="/net/5783.html" target="_blank" style="color:#999">https//www.codepudding.com/net/5783.html</a></p> </div> <div class="detail-arr"> <div class="detail-arr-left">Prev:<a href='/net/5782.html'>. Dat file import</a></div> <div class="detail-arr-right">Next:<a href='/net/5784.html'>C # chi-square test with this way? Or MathNet corresponding method is that?</a></div> </div> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="hot-tags neitags"> <ul> <li><i class="iconfont icon-x-tags"></i> Tags:  </li> <a href='/e/tags/?tagname=ASP.NET' target='_blank'>ASP.NET</a> </ul> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="xiangguan"> <ul class="msg msghead"> <li class="tbname">Related</li> </ul> <ul> </ul> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="flinks"> <ul> <li><i class="iconfont icon-x-tags"></i> Links:  </li> <li class="liflinks"><a target="_blank" href="/" title="CodePudding">CodePudding</a></li> </ul> </div> </div> </div> </div> <div class="footer"> <p><span style="font-size:16px;color:#666;font-weight: bold">About Us:</span>  <a href="https://www.codepudding.com/contact.html">Contact Us</a>      <a href="https://www.codepudding.com/service.html">Terms of Service</a>      <a href="https://www.codepudding.com/privacy.html"> Privacy Policy</a></p> <p class="foot_info">Copyright © 2010-2023,Powered By <a href="/" target="_blank">CodePudding</a> </p> </div> <script type="text/javascript" src="/skin/code/tianhu.js"></script> </body></html>