2016-10-19 40 views
0

我正尝试使用HTTP POST将大文件发送到服务器。我可以发送4kB或更少的文件,但是当我尝试发送一个1.5MB的文件时,似乎有时间了。服务器断开连接而不发送数据为什么Arduino上的HTTP POST无法发送大文件

有谁知道如何解决这个问题?

的代码是: 无效READDATA(){

//Variables for WiFi Shield 
    char ssid[] = "Example";   //your network SSID (name) 
    char pass[] = "Example1";   
    char server[] = "http://example.com"; 

    while (status != WL_CONNECTED) { 
    Serial.print(F("Attempting to connect to SSID: ")); 
    Serial.println(ssid); 

    status = WiFi.begin(ssid, pass); 

    // wait 1 second for connection: 
    delay(1000); 
    } 
    Serial.println(F("Connected to wifi")); 
// #endif 

    // check for the presence of the shield: 
    if (WiFi.status() == WL_NO_SHIELD) { 
    Serial.println(F("WiFi shield not present")); 
    // don't continue: 
    while (true); 
    } 
logfile=SD.open("LOG0038.CSV"); 
filesize=logfile.size(); 
    logfile.close(); 

    int fileLength = 0; 
    fileLength = 137 + filesize + 40; 
    Serial.println(filesize); 

    Serial.println(F("\nStarting connection to server...")); 
    Serial.println(server); 
    // if you get a connection, report back via serial: 
    if (client.connect(server, 80)) { 
    Serial.println(F("connected to server")); 

    // Make a HTTP request: 

    client.setTimeout(Time); 
    client.print(F("POST /uploadf HTTP/1.1\r\n")); 
    client.print(F("Host: example.com\r\n")); 
    client.print(F("User-Agent: Frank/1.0\r\n")); 
    client.print(F("Accept-Encoding: gzip, deflate\r\n")); 
    client.print(F("Accept: */*\r\n")); 
    client.print(F("Connection: keep-alive\r\n")); 
    client.print(F("Content-Length: ")); 
    client.print(fileLength); 
    client.print(F("\r\n")); 
    client.print(F("Content-Type: multipart/form-data; boundary=710ff0c6cf2d4c73b12db64cab12e58c\r\n")); 
    client.print(F("\r\n")); 
    client.print(F("--710ff0c6cf2d4c73b12db64cab12e58c\r\nContent-Disposition: form-data; name=\"file\"; filename=\"")); 
    client.print("1000LOG0032.CSV"); 
    client.print(F("\"")); 
    client.print(F("\r\n")); 
    client.print(F("Content-Type: text/plain\r\n\r\n")); 
    logfile=SD.open("LOG0038.CSV"); 
    while(logfile.available()){ 
    while(logfile.position() < logfile.size()){ 
     String dataBuff = logfile.readStringUntil('\n'); 
     client.print(dataBuff); 
    // Serial.println(dataBuff); 
     client.print("\n"); 
    } 
    } 
    client.print(F("\r\n--710ff0c6cf2d4c73b12db64cab12e58c--\r\n")); 
    //client.flush(); 
    } 

    while(client.connected()){ 
    while (client.available()&& status==WL_CONNECTED) { 
     char c = client.read(); 
    Serial.write(c); 
    } 
    } 

    // if the server's disconnected, stop the client: 
    if (!client.connected()) { 
    Serial.print(F("\r\n")); 
    Serial.println(F("disconnecting from server.")); 
// client.flush(); 
    client.stop(); 

    } 
logfile.close(); 
while (true); 
    } 
+0

服务器是否关闭连接?您是否检查服务器中的HTTP发布大小是否有限制 – FrancescoAzzola

+0

我检查了服务器,并且它对HTTP POST大小没有限制 - 看起来arduino一次只能发送20k数据 – Dave

回答

0

这可能不是一个真正的答案,但遗憾的是我没有必要的信誉来写这个注释。

我对arduino一无所知,但是无论何时使用POST,都应该有一个限制max_post_size的选项。在基本的LAMP设置中,它通常在.httaccess中找到。

我希望这可以帮助您排除故障。