private final class ServerConnectThread2 extends Thread
{
private InputStreamReader _in=null;
private OutputStreamWriter _out=null;
private String _url;
private int _delay;
private String _key;
private String _connectionParameters;
OutputStream os=null;
FileConnection fconn=null;
ServerConnectThread2()
{
_key="";
}
public void run()
{
// check internet connection available
setConnectionStringParameter();
bulkUploaderFlag=true;
HttpConnection connection = null;
try
{
_url="http://xxx/bulkuploader.jsp";
_url= EncodeURL (_url) ;
_url = _url + _connectionParameters;
URLEncodedPostData _postData = new URLEncodedPostData("",false);
_postData.append("totalRecord",""+totalRecord);
int count=0;
while(count < totalRecord)
{
_postData.append("accountID"+count,"C"+(String)accountIDVector.elementAt(count));
_postData.append("deviceID"+count,(String)deviceIDVector.elementAt(count));
_postData.append("timestamp"+count,(String)timestampVector.elementAt(count));
_postData.append("statusCode"+count,(String)statusCodeVector.elementAt(count));
_postData.append("latitude"+count,(String)latitudeVector.elementAt(count));
_postData.append("longitude"+count,(String)longitudeVector.elementAt(count));
_postData.append("gpsAge"+count,(String)gpsAgeVector.elementAt(count));
_postData.append("speedKPH"+count,(String)speedKPHVector.elementAt(count));
_postData.append("heading"+count,(String)headingVector.elementAt(count));
_postData.append("altitude"+count,(String)altitudeVector.elementAt(count));
_postData.append("transportID"+count,(String)transportIDVector.elementAt(count));
//_postData.append("inputMask",""+0);
count++;
}
byte [] postDataBytes = _postData.getBytes();
// Open the connection
connection = (HttpConnection)Connector.open(_url, Connector.READ_WRITE, false);
// Set the request method as GET
connection.setRequestMethod("POST");
//connection.setRequestMethod(HttpConnection.POST);
connection.setRequestProperty("User-Agent","Profile/MIDP-2.0 Configuration/CLDC-1.0");
connection.setRequestProperty("Content-Language", "en-US");
connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
//connection.setRequestProperty("Content-Type","application/octet-stream");
//connection.setRequestProperty("Content-Type","multipart/form-data");
String len =new String(postDataBytes);
System.out.println(len);
connection.setRequestProperty("Content-Length",""+len.length());
os= connection.openOutputStream();
os.write(postDataBytes);
exceptionLogObj.saveLog(" [ "+System.currentTimeMillis() +", sct2 ]");
int rc = connection.getResponseCode();
if(rc == HttpConnection.HTTP_OK)
{
_in = new InputStreamReader(connection.openInputStream());
// Wait for an acknowledgment, in this case an '1' character, for 'Received'.
//char c = (char)_in.read();
int length=0;
exceptionLogObj.saveLog(" [ "+System.currentTimeMillis() +", sct2, http==OK ]\n");
StringBuffer buf = new StringBuffer();
while ((length = _in.read()) != -1) {
char c = (char)length;
buf.append(c);
if(c=='0')
{
exceptionLogObj.saveLog(" [ "+System.currentTimeMillis() +", sct2, c==0,not send in bulk unsucessfully ]\n");
System.out.println("DATA not send in bulk SUCCESSFULLY sct2, c==0");
break;
}
if(c=='1')
{
exceptionLogObj.saveLog(" [ "+System.currentTimeMillis() +", sct2, c==1, send in bulk successfully ]\n");
System.out.println("DATA send in bulk SUCCESSFULLY sct2");
String fullPath = "file:///SDCard/dataLog.txt";
try
{
fconn = (FileConnection) Connector.open(fullPath, Connector.READ_WRITE);
if (fconn.exists())
fconn.delete();
}
catch(Exception e){}
finally
{
if(fconn!=null)
fconn.close();
}
break;
}
}
}
else
{
System.out.println("DATA not send in bulk SUCCESSFULLY sct2");
exceptionLogObj.saveLog(" [ "+System.currentTimeMillis() +", sct2, http not ok ]\n");
}
}
catch (Exception e)
{
exceptionLogObj.saveLog(" [ "+System.currentTimeMillis() +", sct2, exception catch ]\n");
exceptionLogObj.saveLog(" [ "+System.currentTimeMillis() + ", "+e.getMessage()+" ] \n");
System.out.println("DATA not send in bulk SUCCESSFULLY"+e.getMessage());
}
finally
{
try
{
if(_in!=null)
_in.close();
if(_out!=null)
_out.close();
if(os!=null)
os.close();
if(connection!=null)
connection.close();
bulkUploaderFlag=false;
}
catch (IOException ioe)
{
// Do Nothing
}
return;
}
}
0
A
답변
0
나는 "dos.flush()"메소드를 호출해야한다고 생각합니다. 내 코드가 완벽하게 실행되며 postContent는 문자열 버퍼이며 contanins 300KB 문자열입니다.
if (getPostContent() == null) {
httpConnection.setRequestMethod(HttpConnection.GET);
} else {
String type = "application/x-www-form-urlencoded";
byte[] bytes = postContent.toString().getBytes("UTF-8");
httpConnection.setRequestProperty("Content-Type", type);
httpConnection.setRequestProperty("Content-Length", bytes.length + "");
httpConnection.setRequestMethod(HttpConnection.POST); //setupPost method for this conn
DataOutputStream dos = new DataOutputStream(httpConnection.openOutputStream());
dos.write(bytes);
dos.flush();
dos.close();
}
관련 문제
- 1. 블랙 베리에서 Math.pow() 구현
- 2. 블랙 베리에서 쿠키 읽기
- 3. 블랙 베리에서 XML 생성
- 4. 블랙 베리에서 SQLite 사용하기
- 5. 블랙 베리에서 GPS 사용
- 6. 블랙 베리에서 HttpCore 사용하기
- 7. 블랙 베리에서 XML 파싱
- 8. 여러 파일을 업로드 할 수 없습니다.
- 9. libcurl.net으로 http 파일을 업로드 할 수 없습니다.
- 10. asp로 파일을 업로드 할 수 없습니다 : FileUpload
- 11. 때때로 zip 파일을 업로드 할 수 없습니다.
- 12. apache - 2GB 파일을 업로드 할 수 없습니다.
- 13. ASP.NET MVC2로 파일을 업로드 할 수 없습니다.
- 14. 블랙 베리에서 모듈 이름을 얻으려면
- 15. http를 통해 블랙 베리에서 비디오 스트리밍을 할 수 있습니까?
- 16. 블랙 베리에서 BitmapImage를 구성하는 방법
- 17. PHP 업로드 양식 - 200kb 이미지 파일을 업로드 할 수 없습니다.
- 18. 파일 업로드 컨트롤을 통해 파일을 업로드 할 수 없습니다.
- 19. 블랙 베리에서 SMS를 통해 링크를 공유하는 방법
- 20. 블랙 베리에서 .xls (ms 엑셀) 파일을 읽는 방법
- 21. .htaccess를 업로드 할 수 없습니다.
- 22. 블랙 베리에서 페이지 컨트롤을 구현하는 방법
- 23. 블랙 베리에서 페인트 방법을 호출하는 방법
- 24. 블랙 베리에서 트랙 휠 감도를 제어하는 방법
- 25. 블랙 베리에서 화면을 업데이트하는 방법은 무엇입니까?
- 26. 블랙 베리에서 반올림 된 관리자 표시 경계선
- 27. 블랙 베리에서 비디오 스트리밍을 구현하는 방법은 무엇입니까?
- 28. 블랙 베리에서 프로그레시브 인디케이터가 움직이지 않음
- 29. 블랙 베리에서 Google Analytics를 구현하는 방법은 무엇입니까?
- 30. 블랙 베리에서 날짜 형식을 지정하는 방법
어떻게됩니까? 예외가 있습니까? 오류 메시지? 똑같은 일이 일관되게 발생합니까? –
tomcat 웹 서버에서 "null"응답이 있습니다. 내 전체 코드는 시뮬레이터 (10kb 문자열 데이터를 쉽게 전송)를 위해 잘 작동하지만,이 코드를 장치 (Blackberry 9000)에서 실행하면 NULL이 발생합니다. –