【发布时间】:2011-12-19 03:56:17
【问题描述】:
我有以下php代码
curl_setopt($ch, CURLOPT_URL, $URL); curl_setopt($ch, CURLOPT_USERAGENT, $this->_agent); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, $this->_headers); curl_setopt($ch, CURLOPT_ENCODING , "gzip"); curl_setopt($ch, CURLOPT_VERBOSE, false); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 120); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_COOKIEFILE, $this->_cookie_file_path); curl_setopt($ch, CURLOPT_COOKIEJAR, $this->_cookie_file_path); curl_setopt($ch, CURLOPT_POSTFIELDS, '{"folderId":"1","parameters":{"amount":3,"ascending":false,"offset":0,"sort":"date"}}' ); curl_setopt($ch, CURLOPT_POST, 1);但我不明白为什么不工作。我发布 JSON 的 API 表示未收到参数。我的代码有什么问题吗?我认为整个技巧在于 JSON 参数......我不确定如何发送它们,因为我看不到任何带有 http 分析器的“nave->value”对,因为它通常以简单的形式出现......只是没有任何“名称”的 JSON 代码。
【问题讨论】:
-
发送的 Content-Type 是什么?为什么不使用
json_encode? -
@mario 我试过 curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));并且也不工作。默认情况下,我将标题设置为 $headers = array("Expect:", );我看不出它如何与 json_encode 一起工作
-
您必须咨询 API 维护人员。我们只能猜测。
-
@mario 我在此链接上添加了调试信息(萤火虫),因为我无法在 SO 上发布它。它说它的格式不正确(虽然我尝试了几次“格式化它)pastebin.com/Ujdim8t8
-
如果你有使用这个接口并且实际工作的东西,然后使用代理并记录它:p 然后找出你的脚本有什么不同,并消除所有差异(提琴手代理非常适合它甚至支持伪造证书/MITM 攻击,用于监视 HTTPS 加密连接、解码 gzip/deflate 等)