I have a PHP application which send a request to a site and receive back a XML structure.
This worked without problem some weeks ago but now I receive an error 400 on each request.
I debugged the code via eclipse IDE.
If I copy the PHP generated url ($url) and paste it in the browser it works
But with PHP/curl I receive an error 400 >:(
The php code:
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, **$url**);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
$userAgent = 'Mozilla/5.0 (X11; Fedora;Linux x86; rv:60.0) Gecko/20100101 Firefox/60.0';
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
$xml = curl_exec($ch);
$msg = curl_getinfo($ch, CURLINFO_HTTP_CODE);
url generated is
http://catalogue.bnf.fr/api/SRU?version=1.2&operation=searchRetrieve&query=(bib.isbn%20all%20"9782877726351")%20and%20(bib.author%20all%20"Coulon")&recordSchema=unimarcxchange
I tried
- adding the http version via
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1 );
but all versions that I tested give the same error.
- Removing or changing the user agent but this has none effect.
I think that something changed in PHP or in curl but googling gives only a remark about version ==> default is HTTP/2 with PHP 7.4.
curl and php version
# curl -V
curl 7.67.0 (x86_64-suse-linux-gnu) libcurl/7.67.0 OpenSSL/1.1.1d zlib/1.2.11 libidn2/2.3.0 libpsl/0.21.0 (+libidn2/2.2.0) libssh/0.9.2/openssl/zlib nghttp2/1.39.2
Release-Date: 2019-11-06
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: AsynchDNS GSS-API HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz Metalink NTLM NTLM_WB PSL SPNEGO SSL TLS-SRP UnixSockets
# php -v
PHP 7.4.0 (cli) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Xdebug v2.8.0, Copyright (c) 2002-2019, by Derick Rethans
Any idea?
Many thanks in advance
Philippe