简体   繁体   中英

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

here is my form in 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

$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). 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 = '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).

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

Also check if you are behind an NTLM proxy and set that parameter accordingly. 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 . If you absolutely cannot use the shell and cannot figure out how to set the NTLM option in PHP, consider downloading 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

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 .

I think you could also try a regular curl call from console and check if it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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