Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ssl arduino在发出HTTPS GET请求时获得响应301_Ssl_Redirect_Https_Arduino - Fatal编程技术网

Ssl arduino在发出HTTPS GET请求时获得响应301

Ssl arduino在发出HTTPS GET请求时获得响应301,ssl,redirect,https,arduino,Ssl,Redirect,Https,Arduino,我正在制作一个简单的arduino应用程序,向HTTPS站点发送GET请求。我使用的代码与MKRGSM库示例(GsmSslWebClient)中的代码完全相同。但无论出于什么原因,我在连接到HTTPS站点时总是得到相同的响应:“301永久移动”。我知道这意味着什么,我知道你应该只是向标题中指定的位置发出另一个请求。但我不知道我必须改变什么才能访问https站点。我很抱歉我的无知,我知道在这个例子中它清楚地表明它连接到http://www.arduino.cc/asciilogo.txt但是为什么

我正在制作一个简单的arduino应用程序,向HTTPS站点发送GET请求。我使用的代码与MKRGSM库示例(GsmSslWebClient)中的代码完全相同。但无论出于什么原因,我在连接到HTTPS站点时总是得到相同的响应:“301永久移动”。我知道这意味着什么,我知道你应该只是向标题中指定的位置发出另一个请求。但我不知道我必须改变什么才能访问https站点。我很抱歉我的无知,我知道在这个例子中它清楚地表明它连接到
http://www.arduino.cc/asciilogo.txt
但是为什么它与普通的http示例有什么不同呢

我还想在此指出,我已尝试将端口更改为80和客户端设置,以适用于未受保护的http,该http工作正常。所以https不起作用

代码如下:

/*
  Web client

 This sketch connects to a website using SSL through a MKR GSM 1400 board. Specifically,
 this example downloads the URL "http://www.arduino.cc/asciilogo.txt" and
 prints it to the Serial monitor.

 Circuit:
 * MKR GSM 1400 board
 * Antenna
 * SIM card with a data plan

 created 8 Mar 2012
 by Tom Igoe
*/

// libraries
#include <MKRGSM.h>

#include "arduino_secrets.h" 
// Please enter your sensitive data in the Secret tab or arduino_secrets.h
// PIN Number
const char PINNUMBER[]     = SECRET_PINNUMBER;
// APN data
const char GPRS_APN[]      = SECRET_GPRS_APN;
const char GPRS_LOGIN[]    = SECRET_GPRS_LOGIN;
const char GPRS_PASSWORD[] = SECRET_GPRS_PASSWORD;

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

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

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
  bool connected = false;

  // After starting the modem with GSM.begin()
  // attach the shield to the GPRS network with the APN, login and password
  while (!connected) {
    if ((gsmAccess.begin(PINNUMBER) == GSM_READY) &&
        (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) {
      connected = true;
    } else {
      Serial.println("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.print("GET ");
    client.print(path);
    client.println(" HTTP/1.1");
    client.print("Host: ");
    client.println(server);
    client.println("Connection: close");
    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.available() && !client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    // do nothing forevermore:
    for (;;)
      ;
  }
}
/*
网络客户端
此草图通过MKR GSM 1400板使用SSL连接到网站。明确地
此示例下载URL“http://www.arduino.cc/asciilogo.txt"及
将其打印到串行监视器。
线路:
*MKR GSM 1400板
*触角
*带有数据计划的SIM卡
创建于2012年3月8日
汤姆·伊戈
*/
//图书馆
#包括
#包括“arduino_secrets.h”
//请在机密选项卡或arduino_secrets.h中输入您的敏感数据
//密码
const char PINNUMBER[]=SECRET_PINNUMBER;
//APN数据
const char GPRS_APN[]=SECRET_GPRS_APN;
const char GPRS_LOGIN[]=SECRET_GPRS_LOGIN;
const char GPRS_PASSWORD[]=SECRET_GPRS_PASSWORD;
//初始化库实例
GSMSSL客户机;
GPRS;
GSM-gsmAccess;
//URL、路径和端口(例如:arduino.cc)
char服务器[]=“arduino.cc”;
字符路径[]=“/asciilogo.txt”;
int端口=443;//端口443是HTTPS的默认端口
无效设置(){
//初始化串行通信并等待端口打开:
Serial.begin(9600);
而(!串行){
;//等待串行端口连接。仅本机USB端口需要
}
println(“启动Arduino web客户端”);
//连接状态
布尔连接=假;
//使用GSM.begin()启动调制解调器后
//使用APN、登录名和密码将屏蔽连接到GPRS网络
当(!已连接){
如果((gsmAccess.begin(PINNUMBER)=GSM\u READY)&&
(gprs.attachGPRS(gprs\u APN、gprs\u登录、gprs\u密码)=gprs\u就绪)){
连接=真;
}否则{
Serial.println(“未连接”);
延迟(1000);
}
}
Serial.println(“连接…”);
//如果您获得连接,请通过串行方式报告:
if(客户端连接(服务器、端口)){
Serial.println(“已连接”);
//发出HTTP请求:
客户。打印(“获取”);
client.print(路径);
client.println(“HTTP/1.1”);
client.print(“主机:”);
client.println(服务器);
client.println(“连接:关闭”);
client.println();
}否则{
//如果您没有连接到服务器:
Serial.println(“连接失败”);
}
}
void循环(){
//如果有可用的传入字节
//从服务器读取并打印它们:
if(client.available()){
char c=client.read();
连续打印(c);
}
//如果服务器已断开连接,请停止客户端:
如果(!client.available()&&!client.connected()){
Serial.println();
Serial.println(“断开”);
client.stop();
//永远不做任何事:
对于(;;)
;
}
}
这是输出:

Starting Arduino web client.
connecting...
connected
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Thu, 19 Nov 2020 20:24:07 GMT
Content-Type: text/html
Content-Length: 178
Connection: close
Location: https://www.arduino.cc/asciilogo.txt
Strict-Transport-Security: max-age=500; includeSubDomains
X-Frame-Options: SAMEORIGIN
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block

<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center>
</body>
</html>

disconnecting.
启动Arduino web客户端。
连接。。。
有联系的
HTTP/1.1 301永久移动
服务器:nginx
日期:2020年11月19日星期四20:24:07 GMT
内容类型:text/html
内容长度:178
连接:关闭
地点:https://www.arduino.cc/asciilogo.txt
严格的交通安全:最大年龄=500岁;包含子域
X-Frame-Options:SAMEORIGIN
X-Content-Type-Options:nosniff
X-XSS-Protection:1;模式=块
301永久搬迁
301永久搬迁

nginx 断开。
也有可能我只是个傻瓜,答案很清楚,但如果有人能准确地告诉我该做什么,甚至举个例子,那将不胜感激。 除了更改设置以查看它们是否适用于普通http和其他更糟糕的库之外,我没有做过很多尝试。可悲的是,这是我在互联网上所能找到的全部,因为我不太擅长独自处理图书馆。我使用的是arduino mkr gsm 1400

如果我没有提到任何有助于解决这个问题的细节,一定要打电话给我


感谢所有能提前帮助我的人。

当您尝试char server[]=“www.arduino.cc”时会发生什么;而不是char server[]=“arduino.cc”?它不起作用,服务器参数是要在没有“www”的情况下使用的。好吧,服务器正在重写它以包含“www”,因此它与您不一致。