Asp.net mvc 谷歌安全浏览V4-无法发送请求
我一直在研究谷歌安全浏览API——我确信我做的一切都是正确的,但当我尝试连接到API时,我会出错 “对象引用未设置为对象的实例。” 我安装了正确的nuGet软件包 我的代码如下Asp.net mvc 谷歌安全浏览V4-无法发送请求,asp.net-mvc,google-api,safe-browsing,Asp.net Mvc,Google Api,Safe Browsing,我一直在研究谷歌安全浏览API——我确信我做的一切都是正确的,但当我尝试连接到API时,我会出错 “对象引用未设置为对象的实例。” 我安装了正确的nuGet软件包 我的代码如下 try { //cient_info Google.Apis.Safebrowsing.v4.Data.ClientInfo client = new Google.Apis.Safebrowsing.v4.Data.ClientInfo(); client.ClientId = "testapp
try
{
//cient_info
Google.Apis.Safebrowsing.v4.Data.ClientInfo client = new Google.Apis.Safebrowsing.v4.Data.ClientInfo();
client.ClientId = "testapp";
client.ClientVersion = "1";
//thread_info
Google.Apis.Safebrowsing.v4.Data.ThreatInfo threadInfo = new Google.Apis.Safebrowsing.v4.Data.ThreatInfo();
threadInfo.ThreatTypes.Add("MALWARE");
threadInfo.ThreatTypes.Add("SOCIAL_ENGINEERING");
threadInfo.PlatformTypes.Add("WINDOWS");
threadInfo.ThreatEntryTypes.Add("URL");
//url to check
Google.Apis.Safebrowsing.v4.Data.ThreatEntry ITEM = new Google.Apis.Safebrowsing.v4.Data.ThreatEntry();
ITEM.Url = "http://www.google.com.au/";
threadInfo.ThreatEntries.Add(ITEM);
//API Call
var googleClient = new WebClient();
var response = googleClient.DownloadString("https://safebrowsing.googleapis.com/v4/" + client + threadInfo + "&key=myapikey");
var releases = JObject.Parse(response);
return releases.ToString();
}
catch (Exception X)
{
var Error = X.Message;
return Error.ToString();
}
我想我把var response=googleClient.DownloadString
搞砸了,但我不确定什么是正确的调用方法
有人知道吗
干杯您需要输入api密钥
googleClient.DownloadString("https://safebrowsing.googleapis.com/v4/" + client + threadInfo + "&key=myapikey");
我使用了
ThreatMatches.Find()
,它成功了
ThreatMatchesResource.FindRequest request = service.ThreatMatches.Find(
new FindThreatMatchesRequest{Client = client, ThreatInfo = threatInfo});
FindThreatMatchesResponse execute = await request.ExecuteAsync();
var releases = execute.ToString();
你确定你添加了API密钥吗?老实说,我不记得我是怎么修复的。。。干杯唯一重要的是它是固定的:D