Steam Web API - No Result - php

I tried to use use the Steam Web API to get Skin Prices for PUBG Skins. Yesterday it worked well but today the request returns nothing. Not even the "Too many Requests" Error. Just nothing. I tried everything.
With "file_get_contents" and with a curl request
function getRequest($url, $refer = "", $timeout = 10)
{
$ssl = stripos($url,'https://') === 0 ? true : false;
$curlObj = curl_init();
$options = [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_AUTOREFERER => 1,
CURLOPT_USERAGENT => 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)',
CURLOPT_TIMEOUT => $timeout,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_0,
CURLOPT_HTTPHEADER => ['Expect:'],
CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,
];
if ($refer) {
$options[CURLOPT_REFERER] = $refer;
}
if ($ssl) {
//support https
$options[CURLOPT_SSL_VERIFYHOST] = false;
$options[CURLOPT_SSL_VERIFYPEER] = false;
}
curl_setopt_array($curlObj, $options);
$returnData = curl_exec($curlObj);
if (curl_errno($curlObj)) {
//error message
$returnData = curl_error($curlObj);
}
curl_close($curlObj);
return $returnData;
}
I know that it is really hart to work with the API but somehow it has to work. BTW when I request the URL from my local PC it is working well. Maybe it is something of a IP ban. But shouldn't it return at least a error message?

Related

Get Request Working fine with Postman but not with PHP CURL

I have simple GET request on postman and it does working fine
https://www.instagram.com/p/CVhuRABqnAI/?__a=1&__d=dis
When Im using PHP CURL its did not respond me with Json data rather showing logo
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0",
CURLOPT_URL => "https://www.instagram.com/p/CVhuRABqnAI/?__a=1&__d=dis",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
));
$response = curl_exec($curl);
$error = curl_error($curl);
curl_close($curl);
if($error) {
echo "cURL Error:" . $error;
} else {
echo $response;
}
Can some one else me with this?
Finally I might know what to do as I just faced this problem.
Usually, there is just some kind of difference in between postman and curl. Or there is "something" else, because my solution was just to not send any headers at all...

Curl Error : error:14094418:SSL routines:ssl3_read_bytes:tlsv1 alert unknown ca

I'm working on a payment system integration for a website. For now I'm testing on a local computer with xampp. I have submitted a .csr file to the bank server, then they provide me the .crt file. I do have a .key file too.
When I try to submit the certificate and some value to the bank server with including certificate file path (.crt) and .key file, it throws the error:
Curl Error : error:14094418:SSL routines:ssl3_read_bytes:tlsv1 alert unknown ca
My code is:
$twpg_gateway_url = '<bankurl>';
$twpg_cert_file = getcwd().'<.crtfile with path>';
$twpg_key_file = getcwd().'<.keyfile with path>';
$twpg_key_password = '';
$curl = curl_init();
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => false,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_POST => true,
CURLOPT_USERAGENT => 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)',
//CURLOPT_VERBOSE => true,
CURLOPT_URL => $twpg_gateway_url . '/Exec',
CURLOPT_POSTFIELDS => $request,
CURLOPT_HTTPHEADER => array('Content-Type: text/xml'),
CURLOPT_TIMEOUT => 30
);
if ($twpg_cert_file != '') {
$options[CURLOPT_SSLCERT] = $twpg_cert_file;
$options[CURLOPT_SSLKEY] = $twpg_key_file;
$options[CURLOPT_SSLKEYPASSWD] = $twpg_key_password;
}
curl_setopt_array($curl, $options);
$response = curl_exec($curl);
if(!$response)
{
echo "Curl Error : " . curl_error($curl);
}
curl_close($curl);
return $response;

Magento login curl

i'm trying to make a magento login with curl, what I need can be on the same server as magento
There is my code, currently not working:
$data = array(login[username]"=>"email", "login[password]"=>"password");
$url="https://example.com/customer/account/loginPost/";
$options=array();
$ch = curl_init();
$params = http_build_query($params);
$def_options = array(
CURLOPT_URL=>$url,
CURLOPT_SSL_VERIFYPEER=> 0,
CURLOPT_SSL_VERIFYHOST=> 0,
CURLOPT_FOLLOWLOCATION =>1,
CURLOPT_HEADER=>0,
CURLOPT_RETURNTRANSFER =>1,
CURLOPT_USERAGENT=>"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)",
CURLOPT_COOKIESESSION => true,
CURLOPT_COOKIEJAR=> '/tmp/cookies.txt',
CURLOPT_COOKIEFILE=>'/tmp/cookies.txt',
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_POST=> true,
CURLOPT_POSTFIELDS=>$data,
CURLOPT_TIMEOUT => 100,
CURLOPT_VERBOSE=>TRUE,
CURLOPT_STDERR=>$verbose
);
$def_options += $options;
curl_setopt_array($ch,$def_options);
$response = trim(curl_exec($ch));
$info = curl_getinfo($ch);
curl_close($ch);
echo $response;
This simply redirects me on the login page without any error or successful login, it seems to do not send any POST data.
Any advice?
first. You've missed a quote sign at first line:
$data = array("login[username]"=>"email", "login[password]"=>"password");
^
second. change $params = http_build_query($params); to $data = http_build_query($data);
and you are ready to go.

Yet another blank page with cURL

I have read many similar title questions, but none of them worked for me...
The problem is that when I'm sending an cURL query to a website all I get is a blank page.
Here is my code:
<?php
$action = "http://www.website.com/index.php?section=login&do=process";
$fields = array(
'username' => $user,
'rememberMe' => '1'
);
$login = curl_post($action, $fields);
var_dump($login);
function curl_post($url, array $post = NULL, array $options = array())
{
$defaults = array(
CURLOPT_POST => 1,
CURLOPT_HEADER => 0,
CURLOPT_HTTPHEADER => array('Accept-Language: pl,en-us;q=0.7,en;q=0.3', 'Accept-Charset: ISO-8859-2,utf-8;q=0.7,*;q=0.7'),
CURLOPT_USERAGENT => "Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3",
CURLOPT_URL => $url,
CURLOPT_FRESH_CONNECT => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FORBID_REUSE => 1,
CURLOPT_TIMEOUT => 4,
CURLOPT_NOBODY => false,
CURLOPT_POSTFIELDS => http_build_query($post)
);
$ch = curl_init();
curl_setopt_array($ch, ($options + $defaults));
if( !$result = curl_exec($ch))
{
return(curl_error($ch));
}
curl_close($ch);
return $result;
}
?>
Of course I have my cURL enabled in PHP so its not about that.
If you have any ideas, please share!
Update
I have also been trying adding the following lines at the top of my PHP file:
ini_set("display_errors", 1);
error_reporting(E_ALL);
But the problem still appears - result is a blank page. When I use file_get_contents("http://website.com/"); I can see the page content, so it doesnt work with cURL only.
Running this locally and pointing it at Google, I see two things immediately:
PHP Notice: Undefined variable: user
Google returns a 'Error 405 (Method Not Allowed)!!1' error page but probably because I'm trying to post to it
What happens when you define $user and try again?

PHP cURL error: "Empty reply from server"

I have a class function to interface with the RESTful API for Last.FM - its purpose is to grab the most recent tracks for my user. Here it is:
private static $base_url = 'http://ws.audioscrobbler.com/2.0/';
public static function getTopTracks($options = array())
{
$options = array_merge(array(
'user' => 'bachya',
'period' => NULL,
'api_key' => 'xxxxx...', // obfuscated, obviously
), $options);
$options['method'] = 'user.getTopTracks';
// Initialize cURL request and set parameters
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => self::$base_url,
CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => $options,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_TIMEOUT => 30,
CURLOPT_USERAGENT => 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)'
));
$results = curl_exec($ch);
return $results;
}
This returns "Empty reply from server". I know that some have suggested that this error comes from some fault in network infrastructure; I do not believe this to be true in my case. If I run a cURL request through the command line, I get my data; the Last.FM service is up and accessible.
Before I go to those folks and see if anything has changed, I wanted to check with you fine folks and see if there's some issue in my code that would be causing this.
Thanks!
ANSWER: #Jan Kuboschek helped me stumble onto what is (maybe) going on here. By giving CURLOPT_POSTFIELDS an associative array, a particular content-type is specified that may not work with certain RESTful services. A smarter solution is to manually create a URL-encoded version of that data and pass that as the CURLOPT_POSTFIELDS.
For more info, check out: http://www.brandonchecketts.com/archives/array-versus-string-in-curlopt_postfields
A common issue are spaces in the URL - beginning, in the middle, or trailing. Did you check that out?
Edit - per comments below, spacing is not the issue.
I ran your code and had the same problem - no output whatsoever. I tried the URL and with a GET request, the server talks to me. I would do the following:
Use the following as $base_url: $base_url = 'http://ws.audioscrobbler.com/2.0/?user=bachya&period=&api_key=xxx&method=user.getTopTracks';
Remove the post fields from your request.
Edit
I moved your code out of the class since I didn't have the rest and modified it. The following code runs perfect for me. If these changes don't work for you, I suggest that your error is in a different function.
<?php
function getTopTracks()
{
$base_url = 'http://ws.audioscrobbler.com/2.0/?user=bachya&period=&api_key=8066d2ebfbf1e1a8d1c32c84cf65c91c&method=user.getTopTracks';
$options = array_merge(array(
'user' => 'bachya',
'period' => NULL,
'api_key' => 'xxxxx...', // obfuscated, obviously
));
$options['method'] = 'user.getTopTracks';
// Initialize cURL request and set parameters
$ch = curl_init($base_url);
curl_setopt_array($ch, array(
CURLOPT_URL => $base_url,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_TIMEOUT => 30,
CURLOPT_USERAGENT => 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)'
));
$results = curl_exec($ch);
return $results;
}
echo getTopTracks();
?>
The server received your request, but sent an empty response. Check the result of curl_getinfo($ch, CURLINFO_HTTP_CODE) to find out if the server responded with an HTTP error code.
Update: Ok so the server responds with the 100 Continue HTTP status code. In that case, this should solve your problem:
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
I found this here: PHP and cURL: Disabling 100-continue header. Hope it works!
I came acorss the same issue. My Http_code returned 200 but my response was empty. There could be many reasons for this as i experienced.
--Your hedaers might be incorrect
CURLOPT_HTTPHEADER => array('Content-Type:application/json', 'Expect:')
--You might need to send data as post fields in culr and not attached to the URl like url?p1=a1&p2=a2
$data = array (p1=>a1, p2=>a2)
CURLOPT_POSTFIELDS => $data
So your options array would be similar to the below
array(
CURLOPT_URL => $url,
CURLOPT_FAILONERROR => TRUE, // FALSE if in debug mode
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_TIMEOUT => 4,
CURLOPT_HTTPHEADER => array('Content-Type:application/json', 'Expect:'),
CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => $data,
);
According to Last.FM API documentation you should use GET method instead of POST to pass parameters. When I've changed POST to GET I've received the answer about incorrect key.
And here's the code for get Album Info from Laft.FM even if return error:
The Function:
function getAlbum($xml,$artist,$album)
{
$base_url = $xml;
$options = array_merge(array(
'user' => 'YOUR_USERNAME',
'artist'=>$artist,
'album'=>$album,
'period' => NULL,
'api_key' => 'xYxOxUxRxxAxPxIxxKxExYxx',
));
$options['method'] = 'album.getinfo';
// Initialize cURL request and set parameters
$ch = curl_init($base_url);
curl_setopt_array($ch, array(
CURLOPT_URL => 'http://ws.audioscrobbler.com/2.0/',
CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => $options,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTPHEADER => array( 'Expect:' ) ,
CURLOPT_USERAGENT => 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)'
));
$results = curl_exec($ch);
unset ($options);
return $results;
}
Usage:
// Get the XML
$xml_error = getAlbum($xml,$artist,$album);
// Show XML error
if (preg_match("/error/i", $xml_error)) {
echo " <strong>ERRO:</strong> ".trim(strip_tags($xml_error));
}

Categories