duananyu9231 2014-04-11 07:24
浏览 58

从java调用php脚本 - Android

I have the following copyfile.php file inside my main directory with the below code :

<?php
copy("dir1/test.php","dir2/test.php");
?>

Basically just moving a file from dir1 to dir2 (both the directories are already created and are present in my main directory)

I am using the following java code to call my copyfile.php

try {
        URL url;
        url = new URL( "http://www.xyz.com/copyfile.php" );
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        if( conn.getResponseCode() == HttpURLConnection.HTTP_OK ){
                    InputStream is = conn.getInputStream();
                        // do something with the data here
        }else{
                        InputStream err = conn.getErrorStream();
                        // err may have useful information.. but could be null see javadocs for more information
        }
    } catch (MalformedURLException e) {
                    // TODO Auto-generated catch block
                e.printStackTrace();
    } catch (IOException e) {
                    // TODO Auto-generated catch block
            e.printStackTrace();
    }

    return null;
}

The program runs without any errors but the file is not being copied.

But if I paste the above url (http://www.xyz.com/copyfile.php) in the browser it works fine the file gets copied to dir2. Am I doing something wrong? Please help. Thanks in advance :)

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog
    • ¥15 Excel发现不可读取的内容
    • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题