Android发送数据并获得正确的respeonse但在Web服务器上没有数据

时间:2016-05-17 23:46:17

标签: java android http

我希望有人可以提供帮助。

我编写了一个简单的Android应用程序(尝试)将sqlite数据库发送到Web服务器。我在logcat中得到了正确的响应,但在Web服务器上没有任何内容。

Android代码:

String urli = "http:localhost/upload.php";

int bytesRead, bytesAvailable, bufferSize;
byte[] buffer;
int maxBufferSize = 1*1024*1024;
String lineEnd = "\r\n";
String twoHyphens = "--";
String boundary =  "*****";

File dbDirectory = new File("/sdcard/Databases/");
ArrayList<File> database = new ArrayList<>();
for (File fileEntry : dbDirectory.listFiles())
{
    database.add(fileEntry);
    HttpClient httpclient = new DefaultHttpClient();

    HttpPost httppost = new HttpPost(urli);

    URL url = new URL(urli);
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();

    InputStreamEntity reqEntity = new InputStreamEntity(
            new FileInputStream(fileEntry), -1);

    reqEntity.setContentType("binary/octet-stream");
    reqEntity.setChunked(true);

    HttpResponse response = httpclient.execute(httppost);
    String response2 = connection.getResponseMessage();
    Log.i("response", response.toString());
    Log.i("response", response2.toString());

继承logcat:

05-17 19:30:31.118 16679-16801/ I/response: org.apache.http.message.BasicHttpResponse@528d0bdc
05-17 19:30:31.118 16679-16801/I/response: OK
05-17 19:30:31.138 16679-16801/ I/response: org.apache.http.message.BasicHttpResponse@528d069c
05-17 19:30:31.138 16679-16801/ I/response: OK
05-17 19:30:31.158 16679-16801/I/response: org.apache.http.message.BasicHttpResponse@528da700
05-17 19:30:31.158 16679-16801/ I/response: OK
05-17 19:30:31.210 16679-16801/I/response: org.apache.http.message.BasicHttpResponse@5290984c
05-17 19:30:31.210 16679-16801/ I/response: OK
05-17 19:30:31.254 16679-16801/ I/response: org.apache.http.message.BasicHttpResponse@5290f7c0
05-17 19:30:31.254 16679-16801/I/response: OK
05-17 19:30:31.274 16679-16801/ I/response: org.apache.http.message.BasicHttpResponse@52915848
05-17 19:30:31.274 16679-16801/I/response: OK
05-17 19:30:31.298 16679-16801/ I/response: org.apache.http.message.BasicHttpResponse@5291b7bc
05-17 19:30:31.298 16679-16801/ I/response: OK

如果有人可以帮助或指出我正确的方向,我将永远感激不尽。我试图弄明白这一点疯了。

0 个答案:

没有答案