处理 - BufferedOutputStream异常

时间:2015-10-08 03:44:00

标签: java php network-programming processing

我是Java的陌生人,但我正在开发一个Processing的应用,我需要启发。

我在php server的{​​{1}}根目录上运行了127.0.0.1:8080。我的所有.pde都没有错误,以及处理代码的其余部分。

经过仔细分析后,我了解到该错误在下面的函数中。

在告诉我的情况下,引发的异常是什么?以及如何修复代码?

php scripts
//(cont)

void postPicture(){
//load the saved image into an array of bytes
byte[] thisFile=loadBytes(fileName);

//open a new connection to the server
thisClient = new Client(this, "localhost", 80);
//make an HTTP POST request:
thisClient.write("POST " + pictureScriptUrl + " HTTP/1.1\n");
thisClient.write("Host: localhost\n");
//tell the server you're sending the POST in multiple parts
//and send a unique string that will delineate the parts
thisClient.write("Content-Type: multipart/form-data; boundary=");
thisClient.write(boundary + "\n");

//form the beginning of the request
String requestHead ="--" + boundary + "\n";
requestHead +="Content-Disposition: form-data; name=\"file\"; ";
requestHead += "filename=\"" + fileName + "\"\n";
requestHead +="Content-Type: image/jpeg\n\n";

//form the end of the request
String tail="\n\n--" + boundary + "--\n";

//calculate and send the length of the total request
//including the head of the request, the file, and the tail
int contentLength = requestHead.length() + thisFile.length + tail.length();
thisClient.write("Content-Length: " + contentLength + "\n\n");

//send the header of the request, the file and the tail
thisClient.write(requestHead);
thisClient.write(thisFile);
thisClient.write(tail);
}

0 个答案:

没有答案
相关问题