最近我开始使用AWS C ++ SDK取得了一些成功。那些基于HTTPS GET的调用工作正常。对于IoT REST API,我可以创建Things和ListThings。
但是当我调用UpdateThing请求时,调用会挂起,并且在超时时我收到AWS 504网关超时错误。
我尝试过很多东西,但无济于事。似乎很少有已发布的示例可以帮助我解决问题。
AWS DEBUG日志输出位于:
[DEBUG] 2017-01-03 22:08:42 AWSClient [0x7fff755d1000] Request Successfully signed
[DEBUG] 2017-01-03 22:08:42 CurlHandleContainer [0x7fff755d1000] Attempting to acquire curl connection.
[DEBUG] 2017-01-03 22:08:42 CurlHandleContainer [0x7fff755d1000] No current connections available in pool. Attempting to create new connections.
[DEBUG] 2017-01-03 22:08:42 CurlHandleContainer [0x7fff755d1000] attempting to grow pool size by 2
[INFO] 2017-01-03 22:08:42 CurlHandleContainer [0x7fff755d1000] Pool successfully grown by 2
[INFO] 2017-01-03 22:08:42 CurlHandleContainer [0x7fff755d1000] Connection has been released. Continuing.
[DEBUG] 2017-01-03 22:08:42 CurlHandleContainer [0x7fff755d1000] Returning connection handle 0x7f90bc00da00
[DEBUG] 2017-01-03 22:08:42 CurlHttpClient [0x7fff755d1000] Obtained connection handle 0x7f90bc00da00
[DEBUG] 2017-01-03 22:09:42 CurlHttpClient [0x7fff755d1000] Returned http response code 504
[DEBUG] 2017-01-03 22:09:42 CurlHttpClient [0x7fff755d1000] Releasing curl handle 0x7f90bc00da00
[DEBUG] 2017-01-03 22:09:42 CurlHandleContainer [0x7fff755d1000] Releasing curl handle 0x7f90bc00da00
[DEBUG] 2017-01-03 22:09:42 CurlHandleContainer [0x7fff755d1000] Notified waiting threads.
[DEBUG] 2017-01-03 22:09:42 AWSClient [0x7fff755d1000] Request returned error. Attempting to generate appropriate error codes from response
[ERROR] 2017-01-03 22:09:42 AWSClient [0x7fff755d1000] No response body. Response code: 504
代码是:
Aws::IoT::Model::UpdateThingRequest request;
Aws::IoT::Model::AttributePayload payload;
payload.AddAttributes("manufacturer",manufacturer);
payload.AddAttributes("product",product);
payload.AddAttributes("type",type);
payload.SetMerge(true);
request
.WithThingName(name)
.WithAttributePayload(payload);
auto outcome = _client->UpdateThing(request);
if (outcome.IsSuccess()) {
log.info("Sucess");
} else {
log.info("Error: %s: %s",outcome.GetError().GetExceptionName().c_str(),
outcome.GetError().GetMessage().c_str());
}
答案 0 :(得分:1)
我的问题似乎是curl Mac OS X库(7.52.1)处理PATCH请求的方式。默认情况下,它不调用已注册的数据函数(通过CURLOPT_READFUNCTION注册)。
我通过修补CurlHttpClient.cpp文件为PATCH请求添加CURLOPT_POST选项解决了这个问题。