A
A
Alexander Kerzakov2016-09-05 23:21:48
API
Alexander Kerzakov, 2016-09-05 23:21:48

I can't get data using cURL, how to solve the problem?

I'm trying to get the page api.warface.ru/weapon/catalog
using Curl . But the answer is empty. Please tell me what could be the problem? What's wrong?

<?php
$url = "http://api.warface.ru/weapon/catalog";
$user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36";
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$str = curl_exec($ch); 
curl_close($ch);

print_r ($ch);
?>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
imdeveloper, 2016-09-05
@link_web

In your curl you need to do json_decode. You are getting a Json object.
Or do this:

$json = file_get_contents('http://api.warface.ru/weapon/catalog');
$obj = json_decode($json);
var_dump($obj);

D
Dimonchik, 2016-09-05
@dimonchik2013

why do
you need when you put the answer in
?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question