Jeg er ny her på forum, men jeg er simpelthen gået i stå ift. at få en api til at virke.
Det drejer sig om http://cvrapi.dk/ hvor jeg gerne i mit program vil kunne hente CVR oplysninger.
Jeg har forsøgt at tage det kode eksempel de har på hjemmesiden:
Kode: Vælg alt
using System;
using System.Net;
/*
Hoejre klik paa 'References' i 'Solution Explorer'
Tryk paa 'Add reference'
Oeverst i hoejre hjoerne soeger du blot efter 'web.extensions'
System.Web.Extensions skal tilfoejes som reference.
*/
namespace cvropslag
{
class Program {
static void Main(string[] args)
{
ApiResult company = GetCompanyInfo("10150817");
Console.WriteLine("Test: " + company.Name + " - " + company.Version);
Console.ReadLine();
}
public class ApiOwners
{
public string Name { get; set; }
}
public class ApipPoductionunits
{
public string Pno { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public string Zipcode { get; set; }
public string City { get; set; }
public bool @protected { get; set; }
public string Phone { get; set; }
public string Email { get; set; }
public string Fax { get; set; }
public string Startdate { get; set; }
public string Enddate { get; set; }
public string Employees { get; set; }
public string Addressco { get; set; }
public int Industrycode { get; set; }
public string Industrydesc { get; set; }
public int Companycode { get; set; }
public string Companydesc { get; set; }
public string Creditstartdate { get; set; }
public int? Creditstatus { get; set; }
public bool Creditbankrupt { get; set; }
}
public class ApiResult
{
public string VAT { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public string Zipcode { get; set; }
public string City { get; set; }
public bool @protected { get; set; }
public string Phone { get; set; }
public string Email { get; set; }
public string Fax { get; set; }
public string Startdate { get; set; }
public string Enddate { get; set; }
public string Employees { get; set; }
public string Addressco { get; set; }
public int Industrycode { get; set; }
public string Industrydesc { get; set; }
public int Companycode { get; set; }
public string Companydesc { get; set; }
public string Creditstartdate { get; set; }
public int? Creditstatus { get; set; }
public bool Creditbankrupt { get; set; }
public ApiOwners[] Owners { get; set; }
public ApipPoductionunits[] Productionunits { get; set; }
public int T { get; set; }
public int Version { get; set; }
}
public static ApiResult GetCompanyInfo(string name)
{
ApiResult res;
using(var webClient = new WebClient())
{
webClient.Headers["User-Agent"] = "mit projekt";
string resultContent = webClient.DownloadString(string.Format("http://cvrapi.dk/api?search={0}&country=dk", name));
res = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<ApiResult>(resultContent);
}
return res;
}
}
}
Når jeg kører programmet returneres værdien 0, og uanset om jeg ændrer string i getcompanyinfo til et andet CVR nummer, er det samme resultat.
Jeg har også forsøgt ved at ændre "user-agent" og "mit projekt" - uden held
Er der en som har et bud på hvad filan jeg gør forkert?