gpt4 book ai didi

Arduino GSM Shield 网络客户端 302

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

我将 arduino mega 和 Arduino GSM Shield 与 Fyve(vodafone)- Sim 放在一起。从长远来看,我想添加一个 GPS,通过 GSM 模块将位置数据发送到 data.sparkfun.com。为了让我的代码运行,我从 arduino 的 GsmWebClient 示例开始。问题是,我经常收到“发现 HTTP/1.1 302 - 错误”。所以显然我被重定向了。感觉必须有一个非常简单的解决方案,但我无法弄清楚。基本上通读了整个互联网。我真的不知道发生了什么,现在觉得自己很愚蠢。

如果我将 APN 更改为 web.vodafone.de GSM 和 GPRS 连接,但客户端没有。

这是来自序列号的代码和响应:

// libraries
#include <GSM.h>


// PIN Number
#define PINNUMBER "****"

// APN data
#define GPRS_APN "event.vodafone.de" // replace your GPRS APN
#define GPRS_LOGIN "" // replace with your GPRS login
#define GPRS_PASSWORD "" // replace with your GPRS password

// initialize the library instance
GSMClient client;
GPRS gprs;
GSM gsmAccess;

// URL, path & port (for example: arduino.cc)
char server[] = "arduino.cc";
char path[] = "/asciilogo.txt";
int port = 80; // port 80 is the default for HTTP

void setup() {
// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}

Serial.println("Starting Arduino web client.");
// connection state
boolean notConnected = true;

// After starting the modem with GSM.begin()
// attach the shield to the GPRS network with the APN, login and password
while (notConnected) {
Serial.println("connecting gsm");
if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
Serial.println("gsm connected");
delay(1000);
Serial.println("connecting gprs");
if (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY) {
Serial.println("gprs connected");
notConnected = false;
}
else {
Serial.println("gprs Not connected");
delay(1000);
}
}
else {
Serial.println("gsm Not connected");
delay(1000);
}
}

Serial.println("connecting...");

// if you get a connection, report back via serial:
if (client.connect(server, port)) {
Serial.println("connected");
// Make a HTTP request:
client.println("GET /asciilogo.txt HTTP/1.1");
client.print("Host: ");
client.println("www.arduino.cc");
client.println("Connection: close");
client.println();


}
}

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.available() && !client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();

// do nothing forevermore:
for (;;)
;
}
}

Starting Arduino web client.

connecting gsm

gsm connected

connecting gprs

gprs connected

connecting...

connected

HTTP/1.1 302 Found

Date: Thu, 23 Feb 2017 18:13:45 GMT

Server: Apache

Connection: close

Location: https://web.vodafone.de/sbb/redirectToLandingPage?lyt=vodafone&SESSION_TARGET_URL=http%3A%2F%2Fwww.arduino.cc%2Fasciilogo.txt

Content-Length: 0

Vary: User-Agent

Cache-Control: no-transform

Content-Type: text/plain; charset=ISO-8859-1

disconnecting.

好了,给你了。我希望有人能在这里帮助我,那东西快把我逼疯了。

问候阿恩

最佳答案

我只是觉得 Vodafone 检查 http 数据包 header ,如果他们认为有可疑之处,他们会重定向它们。也许您可以尝试向 http-header 添加信息,例如 user-agent?

    // if you get a connection, report back via serial:
if (client.connect(server, port)) {
Serial.println("connected");
// Make a HTTP request:
client.println("GET /asciilogo.txt HTTP/1.1");
client.print("Host: ");
client.println("www.arduino.cc");
client.println("User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko");
client.println("Connection: close");
client.println();
}

Example and info about http-headers

Discussion about Vodafone proxy detection and redirection

关于Arduino GSM Shield 网络客户端 302,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42423713/

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