BlackBerryアプリでJ2MEのHttpConnectionクラスを使用して、Webサーバーにデータを送信しています。HTTPリクエストの本文で画像のコンテンツを送信する必要があります。
これが私がすることです
配列内のファイルのバイトを取得します
HTTP接続を開く
コンテンツタイプヘッダーをimage/jpegとして設定します
接続の出力ストリームを取得します
バイトを出力ストリームに書き込みます
出力ストリームと接続を閉じます
ただし、画像はサーバーにアップロードされません。何が問題なのですか?
ありがとう。
編集-コードを追加する
HttpConnection conn = null;
OutputStream out = null;
try{
conn = new HttpConnection(Connector.open(myURL));
conn.setRequestProperty("Content-Type", "image/jpeg");
conn.setRequestMethod(HttpConnection.POST);
conn.setRequestProperty("Content-Disposition", "form-data");
conn.setRequestProperty("Connection", "Keep-Alive");
out = conn.openOutputStream;
out.write(buffer, 0, buffer.length);
conn.setRequestProperty("Content-Length", buffer.length);
out.flush();
}
catch(Exception e){
e.printStackTrace();
}
finally{
if(out != null)
out.close();
if(conn != null){
System.out.println("" + conn.getResponseCode());
conn.close();
}
}
編集
同じコードを文字列で試してみると、正常に機能し、文字列をサーバーに送信します。しかし、それでも画像バイトには問題があります。