将javascript代码翻译为c#-需要帮助
我有一个使用.NET4的windows应用程序 我从“WarGaming.Net”API获取数据 我通过HttpWebRequest和HttpWebResponse类获得的大部分数据 我的url请求为“” 但我得到“403禁止” 我读了这篇关于如何使用java脚本的文章 我想知道如何将这个请求实现为带有.net元素的c#代码 谢谢将javascript代码翻译为c#-需要帮助,c#,javascript,html,http,httpwebrequest,C#,Javascript,Html,Http,Httpwebrequest,我有一个使用.NET4的windows应用程序 我从“WarGaming.Net”API获取数据 我通过HttpWebRequest和HttpWebResponse类获得的大部分数据 我的url请求为“” 但我得到“403禁止” 我读了这篇关于如何使用java脚本的文章 我想知道如何将这个请求实现为带有.net元素的c#代码 谢谢 RC这是一段PHP脚本,它使用cURL库向服务器发出带有一系列特定头和值的请求 您将要使用.NET等效的WebRequest: 并查看更多的实施示例 function
RC这是一段PHP脚本,它使用cURL库向服务器发出带有一系列特定头和值的请求 您将要使用.NET等效的WebRequest: 并查看更多的实施示例
function getResp($parr) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://cw.worldoftanks.eu".$parr);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_HTTPHEADER,
array(
'Accept: application/json, text/javascript, text/html, */*',
'X-Requested-With: XMLHttpRequest'
)
);
curl_setopt($ch, CURLOPT_REFERER, "http://worldoftanks.eu/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
$c_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
if (curl_getinfo($ch, CURLINFO_CONTENT_TYPE) == 'image/jpeg') {
$response = array();
$response['request_data']['error_message'] = w2u('Site returned JPEG, Maintanace maybe?');
$response = json_encode($response);
}
curl_close($ch);
return $response;
}
print_r( getResp('/clanwars/maps/provinces/regions/1/?ct=json') );