Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.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
我想将我的url作为普通数据从php文件发送到java服务器_Java_Php_Curl - Fatal编程技术网

我想将我的url作为普通数据从php文件发送到java服务器

我想将我的url作为普通数据从php文件发送到java服务器,java,php,curl,Java,Php,Curl,这是我的密码。第二个变量包含我要发送到远程服务器的url。有人能帮我吗 <?php $URLTOPOST="Here is my URL. where i send my data"; $DATATOPOST="http://localhost/newc/index.php"; $data=urlencode($DATATOPOST); $ch=curl_init($URLTOPOST); curl_setopt($ch, CURLOPT_POST, true); curl_setopt(

这是我的密码。第二个变量包含我要发送到远程服务器的url。有人能帮我吗

<?php
$URLTOPOST="Here is my URL. where i send my data";
$DATATOPOST="http://localhost/newc/index.php";
$data=urlencode($DATATOPOST);
$ch=curl_init($URLTOPOST);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$returndata=curl_exec($ch);
echo $returndata;
curl_close($returndata);
?>

您可以像这样构建查询字符串

 **http://www.yoururl.com?data=123&data1=xyz**
或者您可以使用CURL set选项发送如下Post数据

  curl_setopt($ch, CURLOPT_URL,"http://www.yoururl.com/index.php");
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS,
  "var1=value1&var2=value2&var3=value3");

你必须把它包装成一个查询字符串:URL=你的URL。通过这种方式,它将工作并更改您的数据,如查询字符串。