简体   繁体   English

在哪里找到变化的PHP POST数据

[英]Where to find a changing PHP POST data

I logged in with the following code (I summarized it with the most important parts): 我使用以下代码登录(使用最重要的部分进行了总结):

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_parameters);
$result = curl_exec($ch);
curl_close($ch);

In order to know what $post_parameters I had to enter, I used httpfox to analyze the HTTP traffic when I log in manually on my browser. 为了知道我必须输入什么$ post_parameters,当我在浏览器中手动登录时,我使用了httpfox来分析HTTP流量。 The POST Data showed to be like this: POST数据显示如下:

auth_key=880ea6a14ea49e853634fbdc5015a024&referer=http%3A%2F%2Fwww.website.net%2F&ips_username=myUsername&ips_password=myPassword

So I just did this on my script: 所以我只是在我的脚本上这样做:

$post_parameters = "auth_key=".$authKey."&referer=".$referer."&ips_username=".$username."&ips_password=".$password;

I planned to do the same with the function to simulate the topic post, but I have the problem that when I post something manually with the browser and analyze the traffic to find the POST Data, instead of looking like the one for the log in, it looks like this: 我计划对模拟主题发布的功能执行相同的操作,但是我遇到的问题是,当我使用浏览器手动发布内容并分析流量以查找POST数据时,看起来就像登录时那样,它看起来像这样:

-----------------------------20170174379164 // <-- Unknown number
Content-Disposition: form-data; name="st"

0
-----------------------------20170174379164
Content-Disposition: form-data; name="app"

forums
-----------------------------20170174379164
Content-Disposition: form-data; name="module"

post
-----------------------------20170174379164
Content-Disposition: form-data; name="section"

post
-----------------------------20170174379164
Content-Disposition: form-data; name="do"

new_post_do
-----------------------------20170174379164
Content-Disposition: form-data; name="s"

5124060eb013dfa845b1e6b67c3fbfa7 //Changing number which can be found on the previous source code
-----------------------------20170174379164
Content-Disposition: form-data; name="p"

0
-----------------------------20170174379164
Content-Disposition: form-data; name="t"
.
.
.

I want to do the same I did in the other case, that would be something like this: 我要像在其他情况下一样做,那就是这样的:

$post_parameters = "-----------------------------$boundaryNumber
Content-Disposition: form-data; name="st"

0
-----------------------------$boundaryNumber
Content-Disposition: form-data; name="app"

forums
-----------------------------$boundaryNumber
Content-Disposition: form-data; name="module"

post
-----------------------------$boundaryNumber
Content-Disposition: form-data; name="section"

post
-----------------------------$boundaryNumber
Content-Disposition: form-data; name="do"

new_post_do
-----------------------------$boundaryNumber
Content-Disposition: form-data; name="s"

$changingNumber 
-----------------------------$boundaryNumber
Content-Disposition: form-data; name="p"

0
-----------------------------$boundaryNumber
Content-Disposition: form-data; name="t"
.
.
."

but I have the problem that I dont know what number will appear on the boundary line so that I could just put $boundaryNumber everytime it appears on the code. 但是我有一个问题,我不知道边界线上会出现什么数字,因此每次在代码上出现$boundaryNumber我都可以放它。 Is there a way I can know what number will appear? 有没有办法知道会出现什么数字? If there isn't, can I place the number I want or it has to be a specific number so that the POST works? 如果没有,我可以放置我想要的电话号码还是必须是一个特定的电话号码,以便POST能够正常工作?

I hope I explained myself better this time. 我希望这次我能更好地解释自己。

2 obvious problems, you don't urlencode your data, so if the data contains & or = or spaces or ÆØÅ or a bunch of other characters, you'll send the wrong data. 有2个明显的问题,您不必对数据进行urlencode,因此,如果数据包含&=或空格或ÆØÅ或其他字符,则会发送错误的数据。

second problem is that your curl code use application/x-www-urlencoded encoding, but your browser use multipart/form-data -encoding in the POST request body. 第二个问题是您的curl代码使用application/x-www-urlencoded编码,但是您的浏览器在POST请求正文中使用multipart/form-data -encoding。

now with curl_, in order to use use multipart/form-data -encoding, just give CURLOPT_POSTFIELDS an array, and curl will multipart/form-data -encode it for you :) 现在使用curl_,为了使用使用multipart/form-data -encoding,只需给CURLOPT_POSTFIELDS一个数组,curl将为您进行multipart/form-data -encode :)

$post_parameters = array (
        "auth_key" => $authKey,
        "referer" => $referer,
        "ips_username" => $username,
        "ips_password" => $password 
);

edit: fixed some code-breaking typos, had = in the array key name when converting it from urlencoded to php array 编辑:修复了一些代码破译错误,将其从urlencoded转换为php数组时,在数组键名中具有=

as for the confusion about the boundary string, its you, yourself, that decide what the boundary string is. 关于边界字符串的困惑,由您自己决定边界字符串是什么。 usually, its just a bunch of random characters. 通常,它只是一堆随机字符。 its part of the multipart/form-data encoding... but you don't have to worry about that, as curl will make a boundary string for you automatically, and you don't need to know how it works or what it is, curl will take care of it for you. 它是multipart/form-data编码的一部分...但是您不必担心,因为curl会自动为您创建边界字符串,并且您无需知道它的工作原理或含义。 ,curl会为您照顾好它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM