0

I have a windows application using .net 4.

I am getting data from "WarGaming.Net" API.

Most of the data I get By HttpWebRequest and HttpWebResponse classes.

My url request is "http://cw.worldoftanks.eu/clanwars/maps/provinces/regions/1/?ct=json"

But I get "403 Forbidden".

I read this post about how to do it with java script 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') );

And I wonder how could I impliment this request to c# code with .net elements.

Thanks

RC

Mild Fuzz
  • 29,463
  • 31
  • 100
  • 148
RcMan
  • 893
  • 8
  • 16

1 Answers1

1

This is a chunk of PHP scripting that uses the cURL library to make a request to a server with a series of specific headers and values.

You'll want to use the .NET equiv, WebRequest: http://msdn.microsoft.com/en-us/library/system.net.webrequest%28v=vs.110%29.aspx And take a look at cURL with user authentication in C# for more examples of implementing.

Community
  • 1
  • 1
david
  • 11
  • 1