gpt4 book ai didi

rest - 英特尔伽利略 Azure REST 调用

转载 作者:行者123 更新时间:2023-12-03 01:47:12 24 4
gpt4 key购买 nike

我正在尝试通过调用作为 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");

它们都不起作用,有些甚至无法连接然而,即使该 URL 有效并且在不同的网络应用程序中进行了测试(甚至在同一网络上),它也只会返回 404。

我已将 mac 地址替换为设备的地址,并且之前已确认可以通过使其本身成为 Web 服务器来在网络中访问它。基本上它可以获取互联网设置,但由于某种原因无法连接到我的休息服务。任何形式的帮助表示赞赏。谢谢

最佳答案

问题在于没有为调用提供主机。我来自 c# 背景,认为通过使用服务器地址初始化 HttpClient 就足够了,但显然你必须提供这一行

client.println("GET /api/warning HTTP/1.1");
client.println("Host: wack.azurewebsites.net");
client.println("User-Agent: Intel Galileo");
client.println("Connection: close\r\n");

每次您提出请求

关于rest - 英特尔伽利略 Azure REST 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44869658/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com