我正在使用http post将文件上传到我的服务器我有一个简单的方法女巫可以完成工作但是加载...对话框永远不会显示我该如何解决这个问题...这是我的代码
public void send_data() throws IOException
{
HttpURLConnection connection = null;
DataOutputStream outputStream = null;
String lineEnd = "\r\n";
String twoHyphens = "--";
String boundary = "*****";
ProgressDialog dialog = ProgressDialog.show(CaptureTestActivity.this, "",
"Loading. Please wait...", true);
dialog.show();
String urlServer = "http://poi.gps.ro:80/postimg?lat=" + String.valueOf(mDraw.lat) + "&lon=" + String.valueOf(mDraw.lon)+"&comment=" + tmp;
Log.w("DHA", urlServer);
URL url = new URL(urlServer);
if (url != null)
{
Log.w("DHA", "Merge aici");
connection = (HttpURLConnection) url.openConnection();
if (connection != null)
{
Log.w("DHA", "Si aici mere!");
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setRequestMethod("POST");
connection.setRequestProperty("Host", "poi.gps.ro");
connection.setRequestProperty("Connection", "Keep-Alive");
connection.setRequestProperty("Content-Type", "multipart/form-data;boundary=*****");
outputStream = new DataOutputStream(connection.getOutputStream());
outputStream.writeBytes(twoHyphens + boundary + lineEnd);
outputStream.writeBytes("Content-Disposition: form-data; name=\"uploadedfile\";filename=\"" + "PICT0000" +"\"" + lineEnd);
outputStream.writeBytes(lineEnd);
outputStream.write(btarr.toByteArray());
outputStream.writeBytes(lineEnd);
outputStream.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
Log.w("DHA", "Incep trimiterea pozei!");
outputStream.flush();
outputStream.close();
int serverResponseCode = connection.getResponseCode();
String conn = connection.getResponseMessage();
// InputStream in = connection.getInputStream();
// StringWriter writer = new StringWriter();
Log.w("DHA", conn);
Log.w("DHA", "Serverul a raspuns cu " + String.valueOf(serverResponseCode));
if (serverResponseCode == 200)
{
AlertDialog alertDialog;
alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Super :)");
alertDialog.setMessage("Poza a fost trimisa cu success.");
alertDialog.setButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
} });
alertDialog.show();
}
}
}
dialog.dismiss();
}