简体   繁体   English

使用Curl Proxy发布数据不返回任何内容

[英]Post data using Curl Proxy returns no content

When i am posting the data using curl with out proxy is working fine but when i am using proxy my output is null 当我使用不带代理的curl来发布数据时工作正常,但是当我使用代理时,我的输出为null

here is my form in test.php 这是我在test.php中的表格

<form name="result" id="result" action="testdb.php" method="post" target="frame">
<input name="htno" type="text" id="htno"/>
<input type="submit" value="submit"/>
</form>
<iframe name="frame" id="frame" sandbox="allow-same-origin allow-forms allow-scripts" width="700px" height="500px" frameborder="no"/>

and the code in testdb.php is 并且testdb.php中的代码是

$id= $_POST["htno"];
$ch = curl_init();
$curlConfig = array(

CURLOPT_PROXYTYPE       => 'HTTP',
CURLOPT_PROXY           => '218.108.170.163:82',
CURLOPT_HTTPPROXYTUNNEL => '1',
CURLOPT_FOLLOWLOCATION  => '1',
CURLOPT_MAXREDIRS      => '2',
CURLOPT_RETURNTRANSFER => '1',
CURLOPT_CONNECTTIMEOUT => '10',
CURLOPT_USERAGENT      => 'Mozilla/5.0 (X11; U; Linux i686; en-US) 
        AppleWebKit/532.4 (KHTML, like Gecko) 
        Chrome/4.0.233.0 Safari/532.4',
CURLOPT_HTTPHEADER     => array('Referer: engineershub.in/sparcpanel1/b-tech1/btech11.php'),
CURLOPT_URL            => 'http://engineershub.in/sparcpanel1/b-tech1/btech11db.php',
CURLOPT_POST           => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS     => array(
    'id' => "$id"

),
);
curl_setopt_array($ch, $curlConfig);
$result = curl_exec($ch);
echo $result;
curl_close($ch);

the above code is returning null result and if i remove this part 上面的代码返回空结果,如果我删除了这部分

CURLOPT_PROXYTYPE       => 'HTTP',
CURLOPT_PROXY           => '218.108.170.163:82',
CURLOPT_HTTPPROXYTUNNEL => '1',
CURLOPT_FOLLOWLOCATION  => '1',
CURLOPT_MAXREDIRS      => '2',
CURLOPT_RETURNTRANSFER => '1',
CURLOPT_CONNECTTIMEOUT => '10',
CURLOPT_USERAGENT      => 'Mozilla/5.0 (X11; U; Linux i686; en-US) 
        AppleWebKit/532.4 (KHTML, like Gecko) 
        Chrome/4.0.233.0 Safari/532.4',

from the above code then i am getting the output 从上面的代码然后我得到输出

I want the output using proxy, please help me 我想使用代理输出,请帮帮我

I'm assuming here that you need to provide a username/password to go through your proxy server (if you're on windows that can be your windows login credentials depending of course on your network setup). 我在这里假设您需要提供一个用户名/密码来通过您的代理服务器(如果您在Windows上,可以根据自己的网络设置当然是Windows登录凭据)。 It's worth trying to pass those through to see if that helps. 值得尝试让那些人通过,看看是否有帮助。

Try filling out the $username & $password here with your details, and placing it before you do the curl_exec. 尝试在此处填写$ username和$ password的详细信息,然后在执行curl_exec之前将其放置。

$username = 'your_username';
$password = 'your_password';

$headers = array(
    'Proxy-Authorization: BASIC ' . base64_encode("{$username}:{$password}")
); 

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 

If that doesn't work then if you can let us know the specific error you're getting back that'd help by using the following (after you've run the curl_exec). 如果那不起作用,那么如果您可以让我们知道您要返回的特定错误,请使用以下命令(在运行curl_exec之后)将对您有所帮助。

if ($result === false)
{
    print "Error number: " . curl_errno() . "<br>\n";
    print "Error message: " . curl_error() . "<br>\n";
}

Check with your proxy server if you have to provide username and password 请与您的代理服务器联系,是否需要提供usernamepassword

Also check if you are behind an NTLM proxy and set that parameter accordingly. 还要检查您是否在NTLM代理后面,并相应地设置该参数。 I think you should consider this strongly. 我认为您应该认真考虑这一点。 I do not know how to set this parameter in PHP but in BaSH, it's --proxy-ntlm . 我不知道如何在PHP中设置此参数,但是在BaSH中,它是--proxy-ntlm If you absolutely cannot use the shell and cannot figure out how to set the NTLM option in PHP, consider downloading CNTLM . 如果您绝对不能使用该外壳并且无法弄清楚如何在PHP中设置NTLM选项,请考虑下载CNTLM It's a server which sits between your application and your proxy. 它是一台服务器,位于您的应用程序和代理之间。

To know how your CURL operation is coming along, set the verbose parameter, CURLOPT_VERBOSE 要知道您的CURL操作如何进行,请设置详细参数CURLOPT_VERBOSE

As they said you should use CURLOPT_HTTPAUTH option with the desired authentication method (CURLAUTH_BASIC, CURLAUTH_DIGEST, CURLAUTH_GSSNEGOTIATE, CURLAUTH_NTLM, CURLAUTH_ANY, y CURLAUTH_ANYSAFE.) More info here: http://docs.php.net/manual/es/function.curl-setopt.php . 正如他们所说,您应该将CURLOPT_HTTPAUTH选项与所需的身份验证方法结合使用(CURLAUTH_BASIC,CURLAUTH_DIGEST,CURLAUTH_GSSNEGOTIATE,CURLAUTH_NTLM,CURLAUTH_ANY和y CURLAUTH_ANYSAFE。)此处的更多信息: http ://docs.php.net/manual/es/function。 setopt.php

I think you could also try a regular curl call from console and check if it works. 我认为您也可以尝试从控制台进行常规的curl调用,并检查其是否有效。

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

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