Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.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从php发送和接收数据_Php_Android_Wordpress_Http - Fatal编程技术网

使用android从php发送和接收数据

使用android从php发送和接收数据,php,android,wordpress,http,Php,Android,Wordpress,Http,我有一个php文件,类名是youtubetom3。它有一个名为“get”的函数。它工作正常。当我想在服务器上打印它的结果时,我是这样做的 echo youtubetom3::get('https://www.youtube.com/watch?v=sEhy-RXkNo0',youtubetom3::LINK) 问题是我想从android向服务器中的php发送数据,并使用从android发送的数据调用函数“get”,然后将“get”函数的返回数据发送回android。例如,在android中,我发

我有一个php文件,类名是youtubetom3。它有一个名为“get”的函数。它工作正常。当我想在服务器上打印它的结果时,我是这样做的
echo youtubetom3::get('https://www.youtube.com/watch?v=sEhy-RXkNo0',youtubetom3::LINK)
问题是我想从android向服务器中的php发送数据,并使用从android发送的数据调用函数“get”,然后将“get”函数的返回数据发送回android。例如,在android中,我发送名为url的数据。如下所示

public void postData(String toPost) {
// Create a new HttpClient and Post Header

HttpClient httpclient = new DefaultHttpClient();

HttpPost httppost = new HttpPost("http://www.URL.com/yourpage.php");


//This is the data to send

String url = 'https://www.youtube.com/watch?v=sEhy-RXkNo0'; //any data to send



try {

// Add your data

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);

nameValuePairs.add(new BasicNameValuePair("action", url));

httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

// Execute HTTP Post Request

ResponseHandler<String> responseHandler = new BasicResponseHandler();
String response = httpclient.execute(httppost, responseHandler);

//This is the response from a php application
String reverseString = response;
Toast.makeText(this, "response" + reverseString, Toast.LENGTH_LONG).show();

} catch (ClientProtocolException e) {
Toast.makeText(this, "CPE response " + e.toString(), Toast.LENGTH_LONG).show();
// TODO Auto-generated catch block
} catch (IOException e) {
Toast.makeText(this, "IOE response " + e.toString(), Toast.LENGTH_LONG).show();
// TODO Auto-generated catch block
}

}//end postData()
显然,我想告诉你们:我向服务器发送了数据,但在服务器中,我如何获取这些数据并将其与get函数一起使用,然后将数据发送回android? 提前谢谢你。 任何帮助都将不胜感激。
注意:我想在wordpress中运行此php文件。

使用$\u POST全局变量读取发送到此php脚本的数据。因此,
$\u POST['action']
将包含您发送的变量action的字符串值

编辑:

YoutubeToMP3::get(url, YoutubeToMP3::LINK); 
if($_POST['action']){ YoutubeToMP3::get($_POST['action'], YoutubeToMP3::LINK);}