Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Android将XML发送到PHP服务器_Php_Android_Xml_Http Post_Multipart - Fatal编程技术网

使用Android将XML发送到PHP服务器

使用Android将XML发送到PHP服务器,php,android,xml,http-post,multipart,Php,Android,Xml,Http Post,Multipart,我尝试了许多不同的解决方案,将XML文件发布到PHP服务器 响应总是“09-27 10:49:10.550:I/TAG(3950):无法识别文件MIME-TYPE。” 代码的最新版本为: httppost.setHeader("Content-Type","text/xml;charset=\"UTF-8\""); String textToUpload = ""; try { textToUpload = getStringFromFile(fileN

我尝试了许多不同的解决方案,将XML文件发布到PHP服务器

响应总是“09-27 10:49:10.550:I/TAG(3950):无法识别文件MIME-TYPE。”

代码的最新版本为:

    httppost.setHeader("Content-Type","text/xml;charset=\"UTF-8\"");

    String textToUpload = "";
    try {
        textToUpload = getStringFromFile(fileName);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return new StringEntity(textToUpload);
在出现如下连接的init之前:

private void openConnection () throws IOException {
    httpclient = new DefaultHttpClient();
    httppost = new HttpPost(url);
}
在以这种方式处理响应之后:

private int getServerResponse() throws IOException {
    HttpResponse response = httpclient.execute(httppost);
    Log.i("CIAO", EntityUtils.toString(response.getEntity()));
    StatusLine statusLine = response.getStatusLine();
    return statusLine.getStatusCode();
}
    File file = new File(fileName);

    ContentBody fb = new FileBody(file, "text/xml");
    MultipartEntity entity = new MultipartEntity(
            HttpMultipartMode.BROWSER_COMPATIBLE);
    entity.addPart("file", fb);
    httppost.setEntity(entity);
    return entity;
我也尝试过这个解决方案(以及许多不同的解决方案),但没有成功:

    File file = new File(fileName);
    httppost.setHeader("Content-Type","text/xml;charset=UTF-8");

    ContentBody fb = new FileBody(file, "text/xml");
    MultipartEntity entity = new MultipartEntity(
            HttpMultipartMode.STRICT);
    entity.addPart("file", fb);
    httppost.setEntity(entity);

有什么想法吗?

我用这种方法解决了这个问题:

private int getServerResponse() throws IOException {
    HttpResponse response = httpclient.execute(httppost);
    Log.i("CIAO", EntityUtils.toString(response.getEntity()));
    StatusLine statusLine = response.getStatusLine();
    return statusLine.getStatusCode();
}
    File file = new File(fileName);

    ContentBody fb = new FileBody(file, "text/xml");
    MultipartEntity entity = new MultipartEntity(
            HttpMultipartMode.BROWSER_COMPATIBLE);
    entity.addPart("file", fb);
    httppost.setEntity(entity);
    return entity;
我不知道这个问题是严格的还是标题设置。。不管怎样,现在它工作了……)