[英]Arduino Yun not getting response from Azure API
I'm trying to get my Arduino Yun to talk to an API that I'm hosting on Azure.我试图让我的 Arduino Yun 与我在 Azure 上托管的 API 交谈。 I would like to do more complex things in the future, but at the moment I'm just trying to make a GET request over wifi with a single integer as a parameter.我想在未来做更复杂的事情,但目前我只是想通过 wifi 发出一个 GET 请求,使用单个 integer 作为参数。
I'm basically just using the example found here with the url changed.我基本上只是使用 此处找到的示例,其中 url 已更改。 The example works fine, so as far as I'm aware the issue isn't with my board, its with the interaction with Azure.该示例运行良好,据我所知,问题不在于我的电路板,而在于与 Azure 的交互。
HttpClient.get() returns an int as a response (not the regular HTTP response codes, its unique for the library). HttpClient.get() 返回一个 int 作为响应(不是常规的 HTTP 响应代码,它对于库来说是唯一的)。 I got 60 initially, and changing my API to accept http calls (instead of just https) fixed this and made me get a response of 0 instead.我最初得到了 60,然后将我的 API 更改为接受 http 调用(而不仅仅是 https)修复了这个问题,并让我得到了 0 的响应。 0 is the same response that I get from the working Arduino example, but for some reason I'm not actually getting anything in the body of my response, as the client.available() loop is never entered. 0 与我从工作 Arduino 示例中得到的响应相同,但由于某种原因,我的响应正文中实际上没有得到任何内容,因为从未进入 client.available() 循环。
The API works as intended when I go to the url in chrome, so the issue arises somewhere due to how the arduino and azure talk to each other, but I don't know enough about either to figure it out and nowhere that I look seems to point me in the right direction. The API works as intended when I go to the url in chrome, so the issue arises somewhere due to how the arduino and azure talk to each other, but I don't know enough about either to figure it out and nowhere that I look seems为我指明正确的方向。
Any help would be greatly appreciated, thanks.任何帮助将不胜感激,谢谢。
This question, because I don't have a development board, so I can only give you general advice.这个问题,因为我没有开发板,所以只能给你一般的建议。
Knowing the premise, there is no problem with the sample interface in the test code, and you also confirm that your azure api can be accessed through chrome normally.知道了前提,测试代码中的示例界面没有问题,同时你也确认你的azure api可以通过chrome正常访问了。
Troubleshooting steps:故障排除步骤:
Modify the sample code, and print out the returned content in the sample code on the console.修改示例代码,在控制台打印出示例代码中返回的内容。
Explanation: This step is to confirm whether your development board has normally instantiated HttpClient and whether it has sent http get requests normally.说明:这一步是确认你的开发板是否正常实例化了HttpClient,是否正常发送http get请求。
Suggestion: Use a simple test interface that returns string type, such as returning hello world text information, so that you can view the returned data directly on the console.建议:使用返回字符串类型的简单测试接口,比如返回hello world文本信息,这样就可以直接在控制台查看返回的数据。
If the returned value is still 0, it is recommended to turn on application logs at this time and check the log of each request in the portal, so as to ensure whether the development board sends the http request to the azure web app.如果返回值仍然为0,此时建议开启应用日志,查看门户中各个请求的日志,以确保开发板是否向azure Z2567A5EC3005EB7AC89DZ948发送http请求。 The log will record the request information and results in detail.日志会详细记录请求信息和结果。 Modify the development board code according to the log.根据日志修改开发板代码。
If there is no http request information in the azure logs, or the test sample code did not print the returned content at the beginning, then I guess it may be that the driver of the development board or your product has not been installed and debugged properly.如果azure日志中没有http请求信息,或者测试示例代码一开始没有打印返回的内容,那么我猜可能是开发板的驱动或者你的产品没有安装调试好. It is recommended to recheck whether the device is normal.建议重新检查设备是否正常。
PRIVIOUS私人的
Enable CORS
on portal like below.在门户上Enable CORS
,如下所示。
Add *
, then save it to allow all sites.添加*
,然后将其保存以允许所有站点。
Reason:原因:
Via screenshoot, I can see http://127.0.0.1:port
want to run, and I believe if it works, it will send http request by HttpClient
, so we need to enable cors first.通过截图,我可以看到http://127.0.0.1:port
想要运行,我相信如果它工作,它会通过HttpClient
发送 http 请求,所以我们需要先启用 ZB439A4514C277CE186FCC178。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.