搜索API - 使用PHP和cURL时出现V5:404错误 [英] Search API - V5 : 404 error when using PHP and cURL

查看:87
本文介绍了搜索API - 使用PHP和cURL时出现V5:404错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我希望有人能帮助我在这里指出我出错的地方,不要再把头撞到砖墙上。

Hi all, am hoping someone can help me stop banging my head against a brick wall by pointing out where I am going wrong here.

我正在尝试使用认知服务使用PHP和cURL搜索API v5。  我还尝试在API文档中使用PHP代码示例(位于:https://www.microsoft.com/cognitive-services/en-us/bing-web-search-api/documentation)
但仍然遇到同样的问题:404错误。

I am attempting to use the Cognitive Services Search API v5 using PHP and cURL.  I have also tried using the PHP code example in the API documentation (found at: https://www.microsoft.com/cognitive-services/en-us/bing-web-search-api/documentation) and still get the same problem: a 404 error.

使用以下代码:

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://api.cognitive.microsoft.com/bing/v5.0/search?q=bill+gates&count=10&offset=0&mkt=en-us&safesearch=Moderate");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Ocp-Apim-Subscription-Key: XXXXXXXXXX"));

$output = curl_exec($ch);
$reporting = curl_getinfo($ch);

我收到以下报告回报:

Array
(
    [url] => https://api.cognitive.microsoft.com/bing/v5.0/search?q=bill+gates&count=10&offset=0&mkt=en-us&safesearch=Moderate
    [content_type] => application/json
    [http_code] => 404
    [header_size] => 123
    [request_size] => 205
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 0.276298
    [namelookup_time] => 0.153477
    [connect_time] => 0.177758
    [pretransfer_time] => 0.252367
    [size_upload] => 0
    [size_download] => 0
    [speed_download] => 0
    [speed_upload] => 0
    [download_content_length] => 0
    [upload_content_length] => -1
    [starttransfer_time] => 0.276209
    [redirect_time] => 0
    [redirect_url] => 
    [primary_ip] => 104.45.90.247
    [certinfo] => Array
        (
        )

    [primary_port] => 443
    [local_ip] => 149.210.219.109
    [local_port] => 33405
)

有人可以指出我哪里出错了吗?

Can anyone point out for me where I am going wrong, please?

欢呼,克雷格

推荐答案

你好

我确实发现你只是在发送请求标头中的Ocp-Apim-Subscription-Key。除此之外,必须将以下(用户代理,客户端IP,客户端ID,主机)作为请求标头的一部分发送。

I do observe that you are sending only Ocp-Apim-Subscription-Key in the request header. In addition to that, the following ones (user-agent, client ip, client id, host) have to be sent as part of the request header.

User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 822) X-Search-ClientIP: 999.999.999.999 X-MSEdge-ClientID: <blobFromPriorResponseGoesHere> Host: api.cognitive.microsoft.com

了解更多详情,https://msdn.microsoft.com/en-us/library/dn760781.aspx#fullrequest

for more details, https://msdn.microsoft.com/en-us/library/dn760781.aspx#fullrequest

谢谢


这篇关于搜索API - 使用PHP和cURL时出现V5:404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆