J2ME httpConnection getResponseCode () 블록 Nokia N97의 서버에서 대기 답변
-
18-09-2019 - |
문제
Nokia N97 전화에서 서버로 파일을 업로드하면 모든 것이 잘 작동하지만 파일을 업로드 한 후 서버에서 응답을 얻고 싶습니다. 문제는 30 분 이상 만 응답한다는 것입니다. httpconnection.getResponsecode ()에서 코드 블록이 표시되는 것에서 응답을 기다리고 있습니다. 소니 에릭슨에서 테스트했고 응답이 매우 빨리 얻어서 노키아 N97 문제라고 생각합니다. (다른 전화기에서 잘 작동하기 때문에 서버 문제가 아닙니다)
이 일이 왜 노키아에서만 발생하는지 아는 사람이 있습니까?
코드 스 니펫은 다음과 같습니다.
public uploadfile () {
httpConn = (HttpsConnection) Connector.open(url, Connector.READ_WRITE);
...
//set httpConn parameters and request method
...
writeParametersAndFileName(os, "text/plain");
**writeFileToStream(os);**
os.write("\r\n".getBytes());
os.write("--".getBytes());
os.write(boundary.getBytes());
os.write("--".getBytes());
os.write("\r\n".getBytes());
*//here code blocks on Nokia N97. Same thing happens if I use os.flush() after
// I send chunks of the file*
.....
codeResp = httpConn.getResponseCode();
// check condition
checkResponseHeader();
}
공공의 writeFileToStream () {
InputStream is = null;
FileConnection c = null;
try
{
c = (FileConnection) Connector.open("file:///"+ sourcePath, Connector.READ);
if(c.exists()) {
is = c.openInputStream();
long fs = c.fileSize();
while (total < fs) {
byte[] data = new byte[512];
int readAmount = is.read(data,0,512);
total += readAmount;
os.write(data, 0, readAmount);
}
//os.flush();
}
catch (IOException ex) {
//
}
finally
{
//close connection
}
}
해결책
파일이 업로드되었다고 생각합니다.
getResponseCode ()에 대한 호출은 httpConnection이 실제로 서버에 연결하는 첫 번째입니다.
파일을 업로드 할 때까지 반환되지 않으며 아마도 1 분 이상이 걸릴 것입니다.
이것은 JSR-118의 HTTPConnection 사양에 따라 완벽하게 유효한 동작입니다.
"다음 방법은 연결이 설정 상태에있을 때 연결된 상태로의 전환을 유발합니다.
* openInputStream
* openDataInputStream
* getLength
* getType
* getEncoding
* getHeaderField
* getResponseCode
* getResponseMessage
* getHeaderFieldInt
* getHeaderFieldDate
* getExpiration
* getDate
* getLastModified
* getHeaderField
* getHeaderFieldKey
"
이 작업을 시도한 다른 전화는 N97보다 강력하지 않으며 출력 스트림을 플러시해야하므로 사양에 따라 서버에 연결해야합니다.
제휴하지 않습니다 StackOverflow