HTTP请求–始终(每天)相同的响应

时间:2018-11-07 13:42:47

标签: http post request httpresponse

问题摘要

我向“ Microsoft认知服务”的API发出HTTP-POST请求(从网络摄像头上传图片以识别脸部)。它通常有效->在每天的第一个(!)请求中,我都会收到有效且正确的回复。 但是,在第一个请求之后,我得到的所有其他请求(具有不同的图片)总是相同的响应 (我收到的回复与当天的第一个请求相同) 有趣的是:第二天我提出了一个新请求->再一次,我对第一个请求得到了正确的答复

我的系统和我尝试做的事情

我结合智能家居软件“ iobroker”在Raspberry pi 3上运行Raspbian。

我有一个网络摄像头,可将图片发送到文件http://:1024 / photo.jpg 该图片被发送到Microsoft Cognitive Services,以检查在该图片上是否发现了“面部”。如果找到了面部,服务器会在响应中发送有关已识别面部的一些信息(即“ faceId”和一些面部属性,例如“年龄”,“性别”,“微笑”等)。

问题和请求的描述

这是我发送给Microsoft认知服务的请求:

var request = require('request');

// Replace <Subscription Key> with your valid subscription key.
const subscriptionKey = '<my_API_key>';

// You must use the same location in your REST call as you used to get your
// subscription keys. For example, if you got your subscription keys from
// westus, replace "westcentralus" in the URL below with "westus".
const uriBase = 'https://westeurope.api.cognitive.microsoft.com/face/v1.0/detect';

var imageUrl =
    'http://<myIP>:1024/photo.jpg' 
    // Request parameters.
const params = {
    'returnFaceId': 'true',
    'returnFaceLandmarks': 'false',
    'returnFaceAttributes': 'age,gender,headPose,smile,facialHair,glasses,' +
        'emotion,hair,makeup,occlusion,accessories,blur,exposure,noise'
};

const options = {
    uri: uriBase,
    qs: params,

    body: '{"url": ' + '"' + imageUrl + '"}',
    headers: {
        'Content-Type': 'application/json',
        'Cache-Control': 'no-store, max-age=0, must-revalidate', 
        'Pragma' : 'no-cache',
        'Ocp-Apim-Subscription-Key' : subscriptionKey
    }
};
console.log("***starte hier request hochladen ********")
request.post(options, (error, response, body) => {
  if (error) {
    console.log('Error: ', error);
    console.log("***Fehler Zeile 42 *******")
    return;
  }

因此,如上所述: 每天的第一个(!)请求都可以正常工作-如果图片上有面孔,则响应中将包含有关已识别面孔的所有信息。 但是,那天我提出的所有其他请求都会带来完全相同的响应-这意味着-即使图片上有一张不同的面孔(或根本没有面孔),我也总是会收到与第一个请求相同的响应那个那个。 也许是问题所在:我上传的URL和file_name始终相同,但是当然,文件(photo.jpg)的内容会根据每次请求进行更改

我现在想知道

  • 如果此问题来自服务器(或代理?),则服务器使用某种缓存并且始终(一天)给出相同的响应

    • 如果是客户端问题(我的Raspberry),它使用一种缓存并始终上传同一天(当天的第一天)文件

(但是我认为这是一个客户端问题(因此是iobroker或Raspbian),因为如果我的服务器(存储photo.jpg的服务器)处于脱机状态,那么我的node js脚本可以正常工作而没有任何错误消息。

我真的很感谢任何建议或想法如何解决这个问题。 如果您需要更多信息–请让我知道

最好的问候 施罗丁格(Schroedinger)

0 个答案:

没有答案