2014-02-18 68 views
0

我使用.NET 4翻譯javascript代碼爲C# - 需要幫助

我從「WarGaming.Net」 API獲取數據有一個Windows應用程序。

我通過HttpWebRequest和HttpWebResponse類獲得的大部分數據。

我的URL請求是 「http://cw.worldoftanks.eu/clanwars/maps/provinces/regions/1/?ct=json

,但我得到 「403禁止」。

我看到這篇文章有關如何使用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')); 

做到這一點,我不知道我怎麼會impliment這一要求與.NET元素的C#代碼。

感謝

RC

回答