Can't grab $_GET from CURL POST in PHP - php

I've been fighting for the past couple hours with a weird issue on my local and I'm all out of ideas.
I'm trying to setup a local webhook and grab $_GET values from it. It works fine when I type the url in the address bar and hit enter ie.
http://my-local.com/something/?foo=bar
It does not work at all when I try to do the same directly via CURL or wp_remote_post.
I've tried to use CURL both in PHP and Terminal and both don't work. The CURL call returns status 200 OK and the HTML of the site so it's working and it's not being blocked in any way, but it doesn't trigger my PHP code where I check for the $_GET.
$args = array(
'method' => 'POST',
'timeout' => 30,
'redirection' => 5,
'httpversion' => '1.1',
'blocking' => true,
'headers' => array("Content-Type" => "application/json"),
'body' => json_encode('foo'),
'cookies' => array(),
'sslverify' => false
);
$res = wp_remote_post('http://my-local.com/something/?foo=bar', $args);
I'm all out of ideas.
Things I've tried:
Switching from PHP 7.3 -> 7.2
HTTP and HTTPS
Terminal CURL
PHP CURL
WordPress wp_remote_post
127.0.0.1/localhost/my-domain.com
Remote CURL from a webserver -> my local
Set Expect: '' in CURL headers
Nothing.
The PHP logs don't show any errors and I'm not sure what is wrong with my local.
PHP 7.3.19
I'm also using reverse proxy on my Synology and I'm wondering if this can have anything to do with it?
Any help would be highly appreciated!
Thanks!

Related

unable to run soap based API on the server but work well on local pc

I'm working on payment gateway API and API is based on the SOAP request. I have tested it on my local PC (Ubuntu + php 7.2) and it's working fine locally.
my code look like:
$options = array(
'cache_wsdl' => 0,
'trace' => 1,
'stream_context' => stream_context_create(
array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
)
)
);
$soapclient = new SoapClient("domain-name", $options);
but when I moved the code on the server (Cent OS + PHP 5.6) it stop working with following error:
SOAP-ERROR: Parsing WSDL: Couldn't load from domain-name : failed to load external entity domain-name
i know there are lots of similar question have answered on the site (like this, this, this and may more) but I have tried all of them but no luck.
please help me to fix this issue.
thanks.
I had the same problem. my soap API was working on local PC but not working on the server.
then I check the port 8080 status of my server with the following command:
# netstat --listen
or
# netstat -l
then I found that the port was closed. and after opening it SOAP API start working
I hope this will helps you

php SoapClient fails to connect, but command line curl call works

I have a LAMP server (#1) that is communicating via soap with another server (#2) via WSDL. If I issue a curl call on the command line of server 1 to the URL of server 2, it works fine and get the appropriate WSDL response, but a php soapclient to the same URL is getting a "failed to load external entity" error. This was working before when we had a self signed certificate on server 2, but quit working about the same time we upgraded to a CA certificate.
Funny thing is this server is load balanced with another server at a different location (different OS, but same php code/database) and the second server isn't having any issues at all.
Here is the code I am using for the soap client:
function getSoapClient(){
ini_set("soap.wsdl_cache_enabled", 0);
// standard soap client for application service
$post_url = lum_getString("[CAMPAIGN_POST_URL]").
"?enterprise=".lum_getString("[CAMPAIGN_ENTERPRISE]").
"&company=".lum_getString("[CAMPAIGN_COMPANY]");
$options = array(
'trace' => true,
'cache_wsdl' => WSDL_CACHE_NONE,
'exceptions' => 1,
'verifypeer' => false,
'verifyhost' => false,
'allow_self_signed' => true,
'login' => lum_getString("[CAMPAIGN_POST_ID]"),
'password' => lum_getString("[CAMPAIGN_POST_LC]"),
);
$context = stream_context_create(
array(
'user_agent' => 'PHPSoapClient',
'ssl' => array(
'verify_peer' => false,
'allow_self_signed' => true,
),
'https' => array(
'curl_verify_ssl_peer' => false,
'curl_verify_ssl_host' => false,
)
)
);
$options['stream_context'] = $context;
$client = new SoapClient($post_url."&wsdl",$options);
return $client;
}
The curl and soapclient are using the same ports so it shouldn't be a firewall issue.
Any help in identifying the issue or helping me figure what is wrong is greatly appreciated.
Turns out it appears to be a firewall issue. I opened up all access from server 1 to server 2 and things started working. Not too sure what the issue was. I reduced the options to just the login and password, it's still working. Firewalls are often the answer.
Any ideas regarding the firewall, the correct ports, and why it wasn't working is much appreciated.
Why was cURL working and SOAP not?

file_get_contents fails w/ empty exception

I have a strange behaviour of file_get_contents. We are behind a proxy, so I needed to set the context of file_get_contents. The strange thing is, on my PC it works fine, but on other PC or at other location it won't work, running into the max_execution_time timeout.
if ($requestType == 'GET') {
$context = [
'http' => [
'method' => 'GET',
'header' => "Authorization: " . dbQueryHelper::getApiKey () . "\r\n" . "Content-Type: application/x-www-form-urlencoded\r\n",
'proxy' => getenv ( 'PROXY' ),
'request_fulluri' => true
],
'ssl' => array(
'SNI_enabled' => false, // Disable SNI for https over http proxies
'proxy' => getenv('PROXY'),
'request_fulluri' => true,
"verify_peer"=>false,
"verify_peer_name"=>false,
)
];
}
$context = stream_context_create ( $context );
$dataraw = [
'email' => getenv('DEVMAIL'),
'userEmail' => $user->getNickname(),
'production' => getenv('PROD')
];
$data = http_build_query ( $dataraw );
$context = dbQueryHelper::getContext ( 'GET' ); // this gets the context from above
$result = file_get_contents ( getenv('RESTAPIURL') . '/getPernrByEmail?' . $data, false, $context );
$result = json_decode ( $result, true );
I also get no error message on the other PCs, only
Warning: file_get_contents(...): in C:\trainingplan\lib\common.php on line 79
I think the strange thing is that the warning contains no error... We don't think it could be the proxy because I use the same proxy everywhere and can also use different proxies - same behaviour, on my PC it works, on others not. I also tried with disabling Firewall and UAC and other security services on other PCs, doesn't work as well... We have no clue what could be the root cause.
Do you have any idea for me?
We finally found the solution. It was not network related. It is a bug with PHP 5.5 contained in the Google App Engine Launcher Installer. When specified
runtime: php55
in the app.yaml, the above mentioned symptoms occur. When we change the runtime to
runtime: php
it works fine with proxy and everything. This could be kind of problematic, as Google already deprecated usage of "runtime: php" and you can only upload applications with "runtime: php55" to the App Engine servers. But I think a reasonable workaround would be to develop locally with "runtime: php" and change it to "runtime: php55" only for the upload - but I have no idea if that could have other impacts...
Another cause we experienced yesterday was IPv6. In App Engine Launcher v1.9.23 it helps to disabled IPv6 completely in the entwork settings of your PC. After a restart the php-cgi.exe of GAE Launcher connects correctly through the IPv4 proxy.

Getting internal error with Response Status Code 0 on Amazon Marketplace API Requests

I've downloaded Amazon's Marketplace SDK and I'm trying out one of the samples in the samples dir. However, I'm getting an exception with the following details whenever I try it:
Caught Exception: Internal Error
Response Status Code: 0
Error Code:
Error Type:
Request ID:
XML: RequestId: , ResponseContext: , Timestamp:
ResponseHeaderMetadata:
I have got CURL enabled with SSL as well. What am I doing wrong?
This answer is for future reference. For in-depth troubleshooting, see comments on the question.
The empty response indicates a failed connection to the Amazon server. In this case, HTTP worked fine, but HTTPS did not. As turning off CURLOPT_SSL_VERIFYPEER in the cURL settings solved the issue, it appears that the Amazon server was not using a valid SSL certificate.
Having CURLOPT_SSL_VERIFYPEER turned on checks if the requested host has a valid certificate and lets cURL return false if it doesn't. When CURLOPT_SSL_VERIFYPEER is off, invalid certificates (e.g., self-signed) are accepted and return the regular response.
For future reference. In the new version of the SDK the options are referenced in the client.php as follows
private function getDefaultCurlOptions() {
return array (
CURLOPT_POST => true,
CURLOPT_USERAGENT => $this->config['UserAgent'],
CURLOPT_VERBOSE => true,
CURLOPT_HEADERFUNCTION => array ($this, 'headerCallback'),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2
);
}
setting
CURLOPT_SSL_VERIFYPEER => false,
did the trick in my case. As I am not a security expert, however, no recommendation from this point of view. At least its working and you are probably not loosing 1 whole day as I did.
I experienced a very similar connection issue with Amazon. It was the sample files bundled with the Amazon php api, which contain a following configuration array:
$config = array (
'ServiceURL' => $serviceUrl,
'ProxyHost' => null,
'ProxyPort' => -1,
'MaxErrorRetry' => 3,
);
and if this is copied over and not modified
'ProxyPort' => -1,
will result in an attempt to connect through a proxy port -1 which will of course fail (issue tracked by checking curl error). I hope this helps.

Error in cURL request: name lookup timed out

I wrote some code that fill a login form and submit it via post method. Like:
$config = array(
'adapter' => 'Zend_Http_Client_Adapter_Curl',
);
$this->siteObj = new Zend_Http_Client('http://example.com', $config);
$this->siteObj->setCookieJar();
$this->siteObj->setUri('http://example.com/login');
$this->siteObj->setParameterPost( 'data[User][name]', 'user' );
$this->siteObj->setParameterPost( 'data[User][password]', 'password' );
$response = $this->siteObj->request('POST');
its works fine, but some times this error occur:
Error in cURL request: name lookup timed out
Error: An Internal Error Has Occurred.
whats the problem? what can I do to solve it?
I encountered the same problem:
From the shell, curl worked.
From the shell, the PHP script worked.
PHP could not ping the website.
The DNS config was right.
After restarting Apache, it worked. So strange.
It can be a timeout problem.
Try adjusting the connection timeout:
$config = array(
'adapter' => 'Zend_Http_Client_Adapter_Curl',
'timeout' => 100
);
you can also set single curl options:
$config = array(
'adapter' => 'Zend_Http_Client_Adapter_Curl',
'curloptions' => array(
CURLOPT_USERAGENT => 'Zend_Curl_Adapter',
CURLOPT_HEADER => 0,
CURLOPT_VERBOSE => 0,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_TIMEOUT => 10,
CURLOPT_SSL_VERIFYPEER => false,
),
);
If you find out that it is a timeout issue, I would not suggest to increase too much the timeout parameter, but rather to make a for loop with a number of retries.
It means that your DNS server failed to return a response in time. Check your DNS configuration (e.g. /etc/resolv.conf on Linux), and make sure they are alive and functional. Also try to ping the host in the URL from the same sever to get an idea whether the problem only in PHP or the any application running on the server (more likely).

Categories