2017-09-13 93 views
2

截至今天(2017年9月13日),Bing圖片搜索v 5.0是否更改其後端API?Bing圖片搜索v5.0返回錯誤

使用this console,將值爲「multipart/form-data」的頭文件「Content-Type」添加到給出的響應中的期望值。

然而,從我的具有完全相同的參數和頭iOS應用調用時,收到的錯誤響應「RequestParameterInvalidValue; 消息=‘參數具有無效值。’; 參數= imgUrl的;」

下面的代碼工作,截至昨日:

NSString* path = @"https://api.cognitive.microsoft.com/bing/v5.0/images/search"; 
    NSString* skip = [NSString stringWithFormat:@"skip=%li", (long)searchOffset]; 
    NSString* queryString = [NSString stringWithFormat:@"q=%@", searchQuery]; 
    NSArray* array = @[ 
        // Request parameters 
        @"entities=true", 
        @"count=50", 
        skip, 
        @"safeSearch=Strict", 
        queryString 

        ]; 

NSString* string = [array componentsJoinedByString:@"&"]; 
path = [path stringByAppendingFormat:@"?%@", string]; 

NSLog(@"%@", path); 

NSMutableURLRequest* _request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:path]]; 
[_request setHTTPMethod:@"POST"]; 
// Request headers 
[_request setValue:@"multipart/form-data" forHTTPHeaderField:@"Content-Type"]; 
[_request setValue:accessKey forHTTPHeaderField:@"Ocp-Apim-Subscription-Key"]; 
// Request body 
[_request setHTTPBody:[path dataUsingEncoding:NSUTF8StringEncoding]]; 

我可以刪除在測試代碼中的Content-Type頭,並獲得工作的響應,但昨天這個工作我們的生產應用。有沒有解決方法讓我的生產代碼再次運行,而無需重新提交應用程序進行審批?

+0

我昨天實際上經歷過同樣的行爲!我的測試通過了,突然間這個開始失敗,出現了完全相同的錯誤... –

+0

似乎內容類型標題現已被棄用。 –

回答

0

現在也有這個錯誤。試圖調試它,這是我的轉儲返回什麼:

HTTP_Request2_Response {#460 ▼ 
#version: "1.1" 
#code: 400 
#reasonPhrase: "Bad Request" 
#effectiveUrl: 
"https://api.cognitive.microsoft.com/bing/v5.0/images/search?q=cats" 
#headers: array:16 [▼ 
"cache-control" => "no-cache, no-store, must-revalidate" 
"pragma" => "no-cache" 
"content-length" => "169" 
"content-type" => "application/json; charset=utf-8" 
"expires" => "-1" 
"vary" => "Accept-Encoding" 
"server" => "Microsoft-HTTPAPI/2.0" 
"p3p" => "CP="NON UNI COM NAV STA LOC CURa DEVa PSAa PSDa OUR IND"" 
"bingapis-traceid" => "18AAD6F029D1439EB653971FBD07B6EF" 
"x-msedge-clientid" => "260206484A6764FE375C0CB54B826518" 
"x-msapi-userstate" => "d3dd" 
"x-msedge-ref" => "Ref A: 18AAD6F029D1439EB653971FBD07B6EF Ref B: 
SG2EDGE0713 Ref C: 2017-09-14T07:12:07Z" 
"apim-request-id" => "9de68803-fee7-4a56-aa0e-f00e2b43929b" 
"strict-transport-security" => "max-age=31536000; includeSubDomains; 
preload" 
"x-content-type-options" => "nosniff" 
"date" => "Thu, 14 Sep 2017 07:12:06 GMT" 
] 
#cookies: [] 
#lastHeader: "date" 
#body: "{"_type": "ErrorResponse", "instrumentation": {}, "errors": 
[{"code": "RequestParameterInvalidValue", "message": "Parameter has 
invalid value.", "parameter": "i ▶" 
#bodyEncoded: true 

我還以爲有什麼錯我的代碼,但後來我看到,這裏你的線程並得出結論:它是在冰/ Azure的結束一個錯誤。

0

以下curl的作品。但是,昨天我徹底重新編寫了我的微軟認知密鑰,因爲它們被破壞了。我認爲鑰匙可能在幾個月前破裂,但也許只是在昨天。我不必在任何多個測試文件中更改任何參數。

curl "https://api.cognitive.microsoft.com/bing/v5.0/images/search?q=cats" -H "Content-Type: multipart/form-data" -H "Ocp-Apim-Subscription-Key: <My Bing Search API Key 1>" 
0

現在部署中有一個修復程序,可以解決POST請求的問題。