import.io: how to query from c#
<p>I am using import.io to perform some simple query. I need to automate the calls because of the quantity of queries, therefore I am writing a c# client to run all of them.</p>

<p>I can use the API query "magic string" as template to build my queries, if I manually paste them in a browser I see the JSon of the response.</p>

<p>Calling the urls by code instead I always get the 401 unauthorized error.</p>

<p>I tried to set the url to a web browser control, but it reports that site cannot be accessed.</p>

<p><strong>callingApi</strong> is a string with the full url, composed as such (instead of <strong>§</strong> I have the url to be scraped):</p>

<p><a href="https://api.import.io/store/connector/(connector" rel="nofollow">https://api.import.io/store/connector/(connector</a> code)/_query?input=webpage/url:<strong>§</strong>_apikeyadmin=(my key)</p>

<p>(same problem with _apikey instead of _apikeyadmin)</p>

<p>I tried</p>

<pre><code>   WebRequest r = WebRequest.Create(callingApi);
                r.Method = "GET";
                using (var sr = r.GetResponse().GetResponseStream())
                {
                    using (var reader = new StreamReader(sr))
                    {
                        var content = reader.ReadToEnd();
                    }
                }
</code></pre>

<p>and also</p>

<pre><code>   HttpClient client = new HttpClient();
                client.BaseAddress = new Uri(callingApi);

                client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));

                HttpResponseMessage response = client.GetAsync(callingApi).Result;  
                if (response.IsSuccessStatusCode)
        ... here I have error 401 
</code></pre>

<p>Any advice please?</p>