php get数据问题请教
PC客户端通过crul post数据至后台:
http://218.204.14.50/test/?oldip=61.141.251.21&newip=61.141.251.25&urldata=http://detail.ju.taobao.com/home.htm?spm=601#/&agent=Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 732; .NET4.0C; .NET4.0E) &normal=100&error=102
后台PHP获取数据代码:
$oldip=$_GET["oldip"];
$newip=$_GET["newip"];
$urldata=$_GET["urldata"];
$agent=$_GET["agent"];
$normal=$_GET["normal"];
$error=$_GET["error"];
file_put_contents(test.txt,$oldip,FILE_APPEND);
file_put_contents(test.txt,$newip,FILE_APPEND);
file_put_contents(test.txt,$urldata,FILE_APPEND);
file_put_contents(test.txt,$agent,FILE_APPEND);
file_put_contents(test.txt,$normal,FILE_APPEND);
file_put_contents(test.txt,$error,FILE_APPEND);
?>
后台只能获取到oldip、newip、urldata数据,获取不到agent、normal、error数据,请问高手可能是什么原因?如何解决?
非常感谢!
回复讨论(解决方案)
既然是 post,那么怎么用 $_GET 接受呢?
要用 $_POST !
$oldip=$_POST["oldip"];
$newip=$_POST["newip"];
$urldata=$_POST["urldata"];
$agent=$_POST["agent"];
$normal=$_POST["normal"];
$error=$_POST["error"];
file_put_contents(test.txt,$oldip,FILE_APPEND);
file_put_contents(test.txt,$newip,FILE_APPEND);
file_put_contents(test.txt,$urldata,FILE_APPEND);
file_put_contents(test.txt,$agent,FILE_APPEND);
file_put_contents(test.txt,$normal,FILE_APPEND);
file_put_contents(test.txt,$error,FILE_APPEND);
?>
使用$_POST之后,oldip、newip、urldata、agent、normal、error变量的数据都收不到了,这是为什么呢?
谢谢!
你把参数放到 url里面传递了,怎么能获取到数据呢!
$_REQUEST
$_POST
$_GET
都 记录下来,看看值在哪传的
具体传值代码怎么写?贴出来瞧瞧
嗯,你实际是 get 方式传值的
因为有 spm=601 #/
按约定 # 表示锚点,不会传往 文本服务器
所以其后的内容被截断了,所以你接收不到
而用 post 传值时就不会出现这种情况
贴出你的 curl 代码
明显你是用get方式传递的。
get 传递的参数需要用urlencode转一次。
http://218.204.14.50/test/?oldip=61.141.251.21&newip=61.141.251.25&urldata=http://detail.ju.taobao.com/home.htm?spm=601#/&agent=Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 732; .NET4.0C; .NET4.0E) &normal=100&error=102
应该改为
echo 'http://218.204.14.50/test/?oldip='.urlencode('61.141.251.21').'&newip='.urlencode('61.141.251.25').'&urldata='.urlencode('http://detail.ju.taobao.com/home.htm?spm=601#/').'&agent='.urlencode('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 732; .NET4.0C; .NET4.0E) ').'&normal=100&error=102';
http://218.204.14.50/test/?oldip=61.141.251.21&newip=61.141.251.25&urldata=http%3A%2F%2Fdetail.ju.taobao.com%2Fhome.htm%3Fspm%3D601%23%2F&agent=Mozilla%2F4.0+%28compatible%3B+MSIE+6.0%3B+Windows+NT+5.1%3B+SV1%3B+QQDownload+732%3B+.NET4.0C%3B+.NET4.0E%29+&normal=100&error=102
谢谢xuzuning、fdipzone版主的回复
curl代码:
CURL *curl;
CURLcode res;
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if(curl) {
CString url("http://218.204.14.50/test/?oldip=");
url += csoldip;
url += "&newip=";
url += csnewip;
url += "&urldata=";
url += csurldata;
url += "&agent=";
url += csagent;
url += "&normal=";
url += csnormal;
url += "&error=";
url += cserror;
curl_easy_setopt(curl, CURLOPT_URL, CT2A(url));
curl_easy_setopt(curl, CURLOPT_HTTPGET);
res = curl_easy_setopt(curl, CURLOPT_USERAGENT, "tian_test");
res = curl_easy_perform(curl);
if(CURLE_OK == res)
return TRUE;
curl_easy_cleanup(curl);
}
curl_global_cleanup();
客户端使用urlencode转码之后,后台是不是还要解码?
谢谢!
你这是 C++ 还是 C#
有对应于 php urlencode 的函数吗?
如果有,则将 形如 url += csoldip; 的
改为形如 url += urlencode(csoldip); 的
url 编码后,php 端无需解码
哦,忘了写,客户端是C++,我试试。多谢!
urlencode之后还是获取不到agent、normal、error数据,但将urldata值置为test之后,就可以收到数据了,怀疑是不是$_GET长度有限制,如果不用$_GET、$_REQUEST,还有其它解决方案吗?谢谢!
get 方式有 2k 的上限
所以你这的该用 post 方式
http://www.baidu.com/s?wd=c%2B%2B+curl+post&ie=utf-8
urlencode之后还是获取不到agent、normal、error数据,但将urldata值置为test之后,就可以收到数据了,怀疑是不是$_GET长度有限制,如果不用$_GET、$_REQUEST,还有其它解决方案吗?谢谢!
$_GET有2k的限制,改用POST就好了。
谢谢xuzuning 、fdipzone版主的回复,客户端改用POST之后,后台基本可以获取到数据了,但遇到了新的问题,再请教一下:
PC客户端vc ++ crul post数据至后台:
http://218.204.14.50/test/?oldip=61.141.251.21&newip=61.141.251.25&urldata=http://detail.ju.taobao.com/home.htm?uastk=8c3def7900&userid=301115#/&agent=Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 732; .NET4.0C; .NET4.0E) &normal=100&error=102
后台PHP代码:
oldip=$_POST['oldip']; //结果:61.141.251.21
newip=$_POST['newip']; //结果:61.141.251.25
agent=$_POST['agent']; //结果:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 732; .NET4.0C; .NET4.0E)
normal=$_POST['normal']; //结果:100
error=$_POST['error']; //结果:102
以上变量都能正确获取,但urldata获取有问题
urldata=$$_POST['urldata']; //希望获取的内容:http://detail.ju.taobao.com/home.htm?uastk=8c3def7900&userid=301115#/
但实际上获取的内容:http://detail.ju.taobao.com/home.htm?uastk=8c3def7900,无法获取&userid=301115#/,可能是&号分割的问题,请问这种情况应该怎么处理?
你
file_put_contents('test.txt', print_r($_POST,1));
贴出 test.txt 的内容
使用urlencode已解决,再次感谢2位版主的帮助。谢谢!

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

长URL(通常用关键字和跟踪参数都混乱)可以阻止访问者。 URL缩短脚本提供了解决方案,创建了简洁的链接,非常适合社交媒体和其他平台。 这些脚本对于单个网站很有价值

在Facebook在2012年通过Facebook备受瞩目的收购之后,Instagram采用了两套API供第三方使用。这些是Instagram Graph API和Instagram Basic Display API。作为开发人员建立一个需要信息的应用程序

Laravel使用其直观的闪存方法简化了处理临时会话数据。这非常适合在您的应用程序中显示简短的消息,警报或通知。 默认情况下,数据仅针对后续请求: $请求 -

这是有关用Laravel后端构建React应用程序的系列的第二个也是最后一部分。在该系列的第一部分中,我们使用Laravel为基本的产品上市应用程序创建了一个RESTFUL API。在本教程中,我们将成为开发人员

Laravel 提供简洁的 HTTP 响应模拟语法,简化了 HTTP 交互测试。这种方法显着减少了代码冗余,同时使您的测试模拟更直观。 基本实现提供了多种响应类型快捷方式: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

PHP客户端URL(curl)扩展是开发人员的强大工具,可以与远程服务器和REST API无缝交互。通过利用Libcurl(备受尊敬的多协议文件传输库),PHP curl促进了有效的执行

您是否想为客户最紧迫的问题提供实时的即时解决方案? 实时聊天使您可以与客户进行实时对话,并立即解决他们的问题。它允许您为您的自定义提供更快的服务

2025年的PHP景观调查调查了当前的PHP发展趋势。 它探讨了框架用法,部署方法和挑战,旨在为开发人员和企业提供见解。 该调查预计现代PHP Versio的增长
