ContinentalClothing / continentalclothing.com

API documentation and FAQs
0 stars 0 forks source link

fopen(): SSL: Connection reset by peer in /homepages/41/d360276943/htdocs/borrame_continental-error2.php on line 27 #1

Open nkhine opened 8 years ago

nkhine commented 8 years ago

When using PHP to connect to the API, using the following code:

<?php
header('Content-Type: application/json');
$url = 'https://www.continentalclothing.com/api/v2/stock?api_key=<<REPLACE KEY>>';

// Initiate curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json'));
// Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the url
curl_setopt($ch, CURLOPT_URL,$url);
// Execute
$result=curl_exec($ch);
// Closing
curl_close($ch);

// Will dump a beauty json :3
print_r ($result);

$result = file_get_contents($url);
// Will dump a beauty json :3
var_dump(json_decode($result, true));
?>

user gets the following error:


Warning: fopen(): SSL: Connection reset by peer in /homepages/41/d360276943/htdocs/borrame_continental-error2.php on line 27

Warning: fopen(): Failed to enable crypto in /homepages/41/d360276943/htdocs/borrame_continental-error2.php on line 27

Warning: fopen(https://www.continentalclothing.com/api/v2/stock?api_key=<<API KEY>>): failed to open stream: operation failed in /homepages/41/d360276943/htdocs/borrame_continental-error2.php on line 27

Warning: fgets() expects parameter 1 to be resource, boolean given in /homepages/41/d360276943/htdocs/borrame_continental-error2.php on line 29
nkhine commented 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
nkhine commented 8 years ago

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}
activewear commented 8 years ago

All seem ok ---> don't work

php.ini

allow_url_fopen = On

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" }

nkhine commented 8 years ago

@activewear did you try the ssl.php script from the command line? did this work?

can you try, from the server as well?

activewear commented 8 years ago

I try from local server and web server, same message ...

nkhine commented 8 years ago

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"