【发布时间】:2017-07-02 10:11:44
【问题描述】:
我正在尝试通过调用作为 Web 应用程序托管在 Azure 中的 Microsoft Web API(REST 服务)来利用我的 Intel Galileo Gen2 但我得到的只是一个 azure 404 说它找不到我的应用程序
我的arduino上的代码如下
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
char serverName[] = "wack.azurewebsites.net";
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
while(true);
}
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(serverName, 80)) {
Serial.println("connected");
// Make a HTTP request:
client.println("GET /api/warning HTTP/1.0");
client.println();
}
else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
}
void loop()
{
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available()) {
char c = client.read();
Serial.print(c);
}
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
// do nothing forevermore:
while(true);
}
}
我尝试多次更改目标网址
client.println("GET wack.azurewebsites.net/api/warning HTTP/1.0");
client.println("GET api/warning HTTP/1.0");
client.println("GET /api/warning ");
client.println("GET /api/warning HTTP/1.1");
它们都不起作用,有些甚至无法连接 但是它只返回 404,即使该 URL 是有效的,并且在不同的应用程序中甚至在同一网络上都经过测试。
我已将 mac 地址替换为设备的地址,并且之前已确认通过将其设置为 Web 服务器本身可以在网络中访问它。基本上它可以抓取互联网设置,但由于某种原因无法连接到我的休息服务。任何形式的帮助表示赞赏。谢谢
【问题讨论】:
标签: rest azure arduino httpclient intel-galileo