无法获取 Bing 图片搜索 Api 版本 5 到 return 图片
Can't get Bing Image Search Api Version 5 to return images
希望有人能帮助我。我试图让 Bing 版本 5 图像搜索 Api 到 return 一些实际结果,但它似乎不想:(。
当我使用下面 link 中的测试控制台时,它 returns 图像就好了:
https://dev.cognitive.microsoft.com/docs/services/56b43f0ccf5ff8098cef3808/operations/571fab09dbe2d933e891028f/console
至此,我几乎已经从 link 中复制并粘贴了 C# 代码:
https://dev.cognitive.microsoft.com/docs/services/56b43f0ccf5ff8098cef3808/operations/56b4433fcf5ff8098cef380c
所以我最终得到的是这个,减去我删除了我的新版本 5 密钥:
async void MakeRequest()
{
var client = new HttpClient();
var queryString = HttpUtility.ParseQueryString(string.Empty);
// Request headers
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "My Key goes here");
// Request parameters
queryString["q"] = "cats";
queryString["count"] = "10";
queryString["offset"] = "0";
queryString["mkt"] = "en-us";
queryString["safeSearch"] = "Moderate";
var uri = "https://api.cognitive.microsoft.com/bing/v5.0/images/search?" + queryString;
var response = await client.GetAsync(uri);
litTest.Text = response.ToString();
}
给出了这个结果(抱歉,如果有点乱,我还不习惯,任何提示都非常感谢):
StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content:
System.Net.Http.StreamContent, Headers: { Pragma: no-cache Vary:
Accept-Encoding Cache-Control: no-store, must-revalidate, no-cache
P3P: CP="NON UNI COM NAV STA LOC CURa DEVa PSAa PSDa OUR IND"
Set-Cookie: SRCHD=AF=NOFORM; domain=.bingapis.com; expires=Mon,
15-Oct-2018 19:44:57 GMT; path=/ Set-Cookie:
SRCHUID=V=2&GUID=4259560ECDB441FAAF5D7E390BBCF796; expires=Mon,
15-Oct-2018 19:44:57 GMT; path=/ Set-Cookie: SRCHUSR=DOB=20161015;
domain=.bingapis.com; expires=Mon, 15-Oct-2018 19:44:57 GMT; path=/
Set-Cookie: _SS=SID=1992B4120F0069473316BDBD0EE76838;
domain=.bingapis.com; path=/ Set-Cookie:
_EDGE_S=mkt=en-us&F=1&SID=1992B4120F0069473316BDBD0EE76838; path=/; httponly; domain=bingapis.com Set-Cookie: _EDGE_V=1; path=/; httponly;
expires=Mon, 15-Oct-2018 19:44:57 GMT; domain=bingapis.com Set-Cookie:
MUID=14FADE76CCDC68020A5DD7D9CD3B69D8; path=/; expires=Mon,
15-Oct-2018 19:44:57 GMT; domain=bingapis.com Set-Cookie:
MUIDB=14FADE76CCDC68020A5DD7D9CD3B69D8; path=/; httponly; expires=Mon,
15-Oct-2018 19:44:57 GMT BingAPIs-TraceId:
14F0C29C68D24DAA8E845774043CB487 X-MSEdge-ClientID:
14FADE76CCDC68020A5DD7D9CD3B69D8 X-MSAPI-UserState: e7cc X-MSEdge-Ref:
Ref A: 14F0C29C68D24DAA8E845774043CB487 Ref B:
6ABDFD5BE70A83784C9179474D02662D Ref C: Sat Oct 15 12:44:57 2016 PST
apim-request-id: 4d782700-4993-4975-9a9b-e19dea659101 Date: Sat, 15
Oct 2016 19:44:57 GMT Content-Length: 82014 Content-Type:
application/json; charset=utf-8 Expires: -1 }
任何人都可以帮助我做错什么,我的版本 2 工作得很好,但它在 12 月被取消了。
非常感谢您的阅读和浏览:)。
您没有阅读示例中的回复内容。您需要从响应的内容中获取实际的 json,例如:
var response = await client.GetAsync(uri);
litTest.Text = await response.Content.ReadAsStringAsync();
希望有人能帮助我。我试图让 Bing 版本 5 图像搜索 Api 到 return 一些实际结果,但它似乎不想:(。
当我使用下面 link 中的测试控制台时,它 returns 图像就好了: https://dev.cognitive.microsoft.com/docs/services/56b43f0ccf5ff8098cef3808/operations/571fab09dbe2d933e891028f/console
至此,我几乎已经从 link 中复制并粘贴了 C# 代码: https://dev.cognitive.microsoft.com/docs/services/56b43f0ccf5ff8098cef3808/operations/56b4433fcf5ff8098cef380c
所以我最终得到的是这个,减去我删除了我的新版本 5 密钥:
async void MakeRequest()
{
var client = new HttpClient();
var queryString = HttpUtility.ParseQueryString(string.Empty);
// Request headers
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "My Key goes here");
// Request parameters
queryString["q"] = "cats";
queryString["count"] = "10";
queryString["offset"] = "0";
queryString["mkt"] = "en-us";
queryString["safeSearch"] = "Moderate";
var uri = "https://api.cognitive.microsoft.com/bing/v5.0/images/search?" + queryString;
var response = await client.GetAsync(uri);
litTest.Text = response.ToString();
}
给出了这个结果(抱歉,如果有点乱,我还不习惯,任何提示都非常感谢):
StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.StreamContent, Headers: { Pragma: no-cache Vary: Accept-Encoding Cache-Control: no-store, must-revalidate, no-cache P3P: CP="NON UNI COM NAV STA LOC CURa DEVa PSAa PSDa OUR IND" Set-Cookie: SRCHD=AF=NOFORM; domain=.bingapis.com; expires=Mon, 15-Oct-2018 19:44:57 GMT; path=/ Set-Cookie: SRCHUID=V=2&GUID=4259560ECDB441FAAF5D7E390BBCF796; expires=Mon, 15-Oct-2018 19:44:57 GMT; path=/ Set-Cookie: SRCHUSR=DOB=20161015; domain=.bingapis.com; expires=Mon, 15-Oct-2018 19:44:57 GMT; path=/ Set-Cookie: _SS=SID=1992B4120F0069473316BDBD0EE76838; domain=.bingapis.com; path=/ Set-Cookie: _EDGE_S=mkt=en-us&F=1&SID=1992B4120F0069473316BDBD0EE76838; path=/; httponly; domain=bingapis.com Set-Cookie: _EDGE_V=1; path=/; httponly; expires=Mon, 15-Oct-2018 19:44:57 GMT; domain=bingapis.com Set-Cookie: MUID=14FADE76CCDC68020A5DD7D9CD3B69D8; path=/; expires=Mon, 15-Oct-2018 19:44:57 GMT; domain=bingapis.com Set-Cookie: MUIDB=14FADE76CCDC68020A5DD7D9CD3B69D8; path=/; httponly; expires=Mon, 15-Oct-2018 19:44:57 GMT BingAPIs-TraceId: 14F0C29C68D24DAA8E845774043CB487 X-MSEdge-ClientID: 14FADE76CCDC68020A5DD7D9CD3B69D8 X-MSAPI-UserState: e7cc X-MSEdge-Ref: Ref A: 14F0C29C68D24DAA8E845774043CB487 Ref B: 6ABDFD5BE70A83784C9179474D02662D Ref C: Sat Oct 15 12:44:57 2016 PST apim-request-id: 4d782700-4993-4975-9a9b-e19dea659101 Date: Sat, 15 Oct 2016 19:44:57 GMT Content-Length: 82014 Content-Type: application/json; charset=utf-8 Expires: -1 }
任何人都可以帮助我做错什么,我的版本 2 工作得很好,但它在 12 月被取消了。
非常感谢您的阅读和浏览:)。
您没有阅读示例中的回复内容。您需要从响应的内容中获取实际的 json,例如:
var response = await client.GetAsync(uri);
litTest.Text = await response.Content.ReadAsStringAsync();