我将Arduino Mega和Arduino GSM Shield带有FYVE(Vodafone) - SIM卡在一起。长期,我想添加一个GPS,通过GSM模块将位置数据发送到Data.sparkfun.com。为了使我的代码运行,我从Arduino的GSMwebClient示例开始。问题是,我不断获得" HTTP/1.1 302 - 错误"。因此,显然我被重定向。感觉到必须有一个简单的解决方案,但我无法弄清楚。基本上可以通过整个互联网阅读。我真的不知道WTH正在进行中,现在感觉很愚蠢。
如果我将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 (;;)
;
}
}
启动Arduino Web客户端。
连接GSM
GSM连接
连接GPRS
gprs connected
连接...
连接
http/1.1 302找到
日期:THU,2017年2月23日18:13:45 GMT
服务器:apache
连接:关闭
位置: https://web.vodafone.de/sbb/redirecttolandingpage?lyt=vodafone&amp;session_target_url =
内容长度:0
变化:用户代理
缓存控制:no-Transform
content-type:text/plain;charset = ISO-8859-1
断开连接。
好吧,你有。我希望有人可以在这里帮助我,那东西让我发疯。
向Arne
我刚感觉到沃达丰检查http-packet标头,如果他们认为有些可疑,他们会重定向。也许您可以尝试将信息添加到HTTP-Header,例如用户代理?
// 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();
}
示例和有关http-Headers的信息
讨论沃达丰代理检测和重定向
好吧,我解决了奇迹。听起来很愚蠢:在SIM上没有选择互联网的关税。我从主管那里得到它,并且确定它已经启用了。不是。失败了那个。
大多数时候,302错误是由于SIM卡信用不足