我正在.net中做一个跨域帖子,但在网上他们为我提供了php示例....我想将php代码转换为.net。请帮忙。
<?php
header('Content-type: text/html');
header('Access-Control-Allow-Origin: *');
$uri = 'http'. ($_SERVER['HTTPS'] ? 's' : null) .'://'. $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
echo('<p>This information has come from <a href="' . $uri . '">' . $uri . '</a></p>');
?>
答案 0 :(得分:5)
尝试这样的事情: -
System.Net.WebRequest request = base.GetWebRequest(uri);
request.Headers.Add("Content-type", "text/html");
request.Headers.Add("Access-Control-Allow-Origin", "*");
$_SERVER
相当于Request.ServerVariables[]