Arduino的GSM Shield WebClient 302 [英] Arduino GSM Shield WebClient 302

查看:103
本文介绍了Arduino的GSM Shield WebClient 302的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I put an arduino mega and the Arduino GSM Shield with a Fyve(vodafone)- Sim together. Long term I want to add a GPS to send position-data via the GSM module to data.sparkfun.com. In order to get my code running, I started with the GsmWebClient example from arduino. The problem is, that I constantly get the "HTTP/1.1 302 Found - Error". So apparently I get redirected. Got the feeling that there has to be a pretty much easy solution, but I cant figure it out. Basically read through the whole internet. I really dont know wth is going on and feel rather stupid now.

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

If i change the APN to web.vodafone.de GSM and GPRS connect, but the client doesnt.

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

Here comes the code and the response from the serial:

// 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客户端.

Starting Arduino web client.

连接gsm

gsm已连接

连接gprs

gprs已连接

正在连接...

已连接

找到HTTP/1.1 302

HTTP/1.1 302 Found

日期:2017年2月23日,星期四,格林尼治标准时间

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

服务器:Apache

Server: Apache

连接:关闭

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

内容长度:0

变化:用户代理

Cache-Control:无需转换

Cache-Control: no-transform

Content-Type:文本/纯文本; charset = ISO-8859-1

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

断开连接.

好吧,那里有.我希望有人可以在这里帮助我,这些东西使我发疯.

Well, there you have it. I hope someone can help me here, that stuff is driving me crazy.

关于Arne

推荐答案

我只是觉得Vodafone正在检查http-packet标头,如果他们认为可疑的内容,则将其重定向.也许您可以尝试将信息添加到http-header中,例如user-agent?

I just got feeling that Vodafone checks http-packet headers and if there is something that they think suspicious, they redirect them. Maybe you could try to add information to http-header, like 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();
    }

有关http-header的示例和信息

讨论沃达丰代理检测和重定向

这篇关于Arduino的GSM Shield WebClient 302的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆