2
我正在使用以太網shield在Arduino設備上發出發佈請求。該服務器是一個Node.js服務器,並且我已經處理了發佈請求服務器端,同樣的結果都是福爾馬林和強大的。 POST被處理,但它不能完成文件傳輸。Arduino POST未能完成
loadstart:{ 「時間」:1339574854222} 「與BytesReceived」:178, 「filesCompleted」:0
這是發送後的代碼:
String boundary = "--73249889599006000";
String URL = "/upload";
String contentType = "text/plain";
String fileName = "text.txt";
void sendData(){
String thisFile = "This is not the contents of thisFile";
Serial.println("connecting...");
// If you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println("connected");
// Make a HTTP request:
String postHeader = "POST " + URL + " HTTP/1.1\n";
postHeader += "Content-Type: multipart/form-data; boundary=";
postHeader += boundary + "\n";
postHeader += "Host: 192.168.3.78\n";
postHeader += "User-Agent: Arduino\n";
postHeader += "Referer: http://192.168.3.78/upload\n";
String requestHead = "\n--" + boundary + "\n";
requestHead += "Content-Disposition: form-data; name=\"upload\"; filename=\"" + fileName + "\"\n";
requestHead += "Content-Type: " + contentType + "\n\n";
String tail = "\n--" + boundary + "--\n\n";
int contentLength = requestHead.length() + thisFile.length() + tail.length();
postHeader += "Content-Length: " + String(contentLength, DEC) + "\n\n";
char charBuf0[postHeader.length() + 1];
postHeader.toCharArray(charBuf0, postHeader.length() + 1);
client.write(charBuf0);
char charBuf1[requestHead.length() + 1];
postHeader.toCharArray(charBuf1, requestHead.length() + 1);
client.write(charBuf1);
char charBuf2[thisFile.length() + 1];
postHeader.toCharArray(charBuf2, thisFile.length() + 1);
client.write(charBuf2);
char charBuf3[tail.length() + 1];
postHeader.toCharArray(charBuf3, tail.length() + 1);
client.write(charBuf3);
}
我會嘗試從計算機發送確切的有效負載,看看這是Arduino的問題還是您正在創建的有效負載的問題。 – Pawel
當然:[POST分析工具](http://stackoverflow.com/questions/1087185/http-testing-tool-easily-send-post-get-put)我發現telnet是最好的,因爲你得到的反饋線按行。從arduino粘貼串行輸出到telnet lbl,沖洗,重複。 – J0hnG4lt