Open nkhine opened 8 years ago
Testing the code from my local machine works fine:
$ php api.php
[615]=>
array(6) {
["sku"]=>
string(8) "EP43-WH3"
["name"]=>
string(37) "WOMEN’S TENCEL BLEND SLEEVELESS TOP"
["colour"]=>
string(5) "White"
["size"]=>
string(1) "L"
["stock"]=>
int(405)
["inProduction"]=>
NULL
}
[616]=>
array(6) {
["sku"]=>
string(8) "EP44-BL1"
["name"]=>
string(27) "WOMEN’S TENCEL BLEND VEST"
["colour"]=>
string(5) "Black"
["size"]=>
string(1) "S"
["stock"]=>
int(315)
["inProduction"]=>
NULL
}
so i think the issue is to do with your server / php configuration, specifically support for SSL
you can test SSL support by running the following script
$ vi ssl.php
$w = stream_get_wrappers();
echo 'openssl: ', extension_loaded ('openssl') ? 'yes':'no', "\n";
echo 'http wrapper: ', in_array('http', $w) ? 'yes':'no', "\n";
echo 'https wrapper: ', in_array('https', $w) ? 'yes':'no', "\n";
echo 'wrappers: ', var_dump($w);
executing it, you should get
$ php ssl.php
openssl: yes
http wrapper: yes
https wrapper: yes
wrappers: array(12) {
[0]=>
string(5) "https"
[1]=>
string(4) "ftps"
[2]=>
string(13) "compress.zlib"
[3]=>
string(14) "compress.bzip2"
[4]=>
string(3) "php"
[5]=>
string(4) "file"
[6]=>
string(4) "glob"
[7]=>
string(4) "data"
[8]=>
string(4) "http"
[9]=>
string(3) "ftp"
[10]=>
string(4) "phar"
[11]=>
string(3) "zip"
}
in your php.ini file check to see if php_openssl is enabled and set allow_url_fopen to On
allow_url_fopen = On
here is a python version
>>> import sys
>>> import requests
>>> r = requests.get('https://www.continentalclothing.com/api/v2/stock?api_key=API KEY')
>>> r.json()
>>> for x in r.json():
... print x
... sys.exit()
...
{u'sku': u'CAT15', u'name': u'CONTINENTAL CLOTHING 2015 CATALOGUE', u'colour': u'', u'size': u'', u'inProduction': None, u'stock': 2561}
php.ini
openssl: yes http wrapper: yes https wrapper: yes wrappers: array(12) { [0]=> string(5) "https" [1]=> string(4) "ftps" [2]=> string(13) "compress.zlib" [3]=> string(14) "compress.bzip2" [4]=> string(3) "php" [5]=> string(4) "file" [6]=> string(4) "glob" [7]=> string(4) "data" [8]=> string(4) "http" [9]=> string(3) "ftp" [10]=> string(4) "phar" [11]=> string(3) "zip" }
@activewear did you try the ssl.php script from the command line? did this work?
can you try, from the server as well?
I try from local server and web server, same message ...
that is very strange, perhaps it is issue with your openssl version, as from the php.ini file i see you're using OpenSSL 0.9.8o 01 Jun 2010 try to update this to later version, my version is
$ openssl version -a
OpenSSL 1.0.1f 6 Jan 2014
built on: Thu Jun 11 15:28:12 UTC 2015
platform: debian-amd64
options: bn(64,64) rc4(16x,int) des(idx,cisc,16,int) blowfish(idx)
compiler: cc -fPIC -DOPENSSL_PIC -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -m64 -DL_ENDIAN -DTERMIO -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -Wl,-Bsymbolic-functions -Wl,-z,relro -Wa,--noexecstack -Wall -DMD32_REG_T=int -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM
OPENSSLDIR: "/usr/lib/ssl"
When using PHP to connect to the API, using the following code:
user gets the following error: