【发布时间】:2014-02-18 08:16:07
【问题描述】:
我有一个使用 .net 4 的 Windows 应用程序。
我正在从“WarGaming.Net”API 获取数据。
我通过 HttpWebRequest 和 HttpWebResponse 类获得的大部分数据。
我的网址请求是“http://cw.worldoftanks.eu/clanwars/maps/provinces/regions/1/?ct=json”
但我得到“403 Forbidden”。
我阅读了这篇关于如何使用 java 脚本 https://github.com/thunder-spb/wot-api-description/issues/28#issuecomment-33958289 进行操作的帖子
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') );
我想知道如何将这个请求隐含到带有 .net 元素的 c# 代码中。
谢谢
RC
【问题讨论】:
标签: c# javascript html http httpwebrequest