2012-07-02 68 views
1

我在.net中做了一個跨域的帖子,但在網絡中他們提供了我的PHP例子....我想將PHP代碼轉換爲.net。請幫忙。什麼是在C#中的PHP的等效代碼

<?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>'); 
    ?> 

回答

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[]

+0

此外,添加的輸出中! –

相關問題