Currently, I am trying to connect PHP website with MS Dynamics 2013. I found the following example (https://github.com/rocketeer007/php-dynamics-crm-2011) to connect to but it is not working.
I provided the configuration but is getting following error i.e.
string(576) "http://www.w3.org/2005/08/addressing/soap/faults:Sendera:InvalidSecurity
An error occurred when verifying security for the message."
I couldn't find more information about the soap response.
Here is the more information that I am sending in my request i.e.
**NOTE: For example purposes below I have changed the URLs**
//Parameters values used in the below CURL
$soapUrl = https://example.crmserver.com/adfs/services/trust/13/usernamemixed
$headers = 'POST /adfs/services/trust/13/usernamemixed HTTP/1.1
Host: adfs.crmserver.com
Connection: Keep-Alive
Content-type: application/soap+xml; charset=UTF-8
Content-length: 1481'
$content = '<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<a:Action s:mustUnderstand="1">http://docs.oasis-open.org/ws-sx/ws-trust/200512/RST/Issue</a:Action>
<a:ReplyTo>
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</a:ReplyTo>
<a:To s:mustUnderstand="1">https://adfs.crmserver.co.nz/adfs/services/trust/13/usernamemixed</a:To>
<o:Security xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" s:mustUnderstand="1">
<u:Timestamp u:Id="_0">
<u:Created>2015-07-16T04:09:52.00Z</u:Created>
<u:Expires>2015-07-16T04:10:52.00Z</u:Expires>
</u:Timestamp>
<o:UsernameToken u:Id="user">
<o:Username>desktop\abc_service.mrl</o:Username>
<o:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">password</o:Password>
</o:UsernameToken>
</o:Security>
</s:Header>
<s:Body>
<trust:RequestSecurityToken xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">
<wsp:AppliesTo xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
<a:EndpointReference>
<a:Address>https://dev2013.crm.crmserver.co.nz/XRMServices/2011/Discovery.svc</a:Address>
</a:EndpointReference>
</wsp:AppliesTo>
<trust:RequestType>http://docs.oasis-open.org/ws-sx/ws-trust/200512/Issue</trust:RequestType>
</trust:RequestSecurityToken>
</s:Body>
// Request
$cURLHandle = curl_init();
curl_setopt($cURLHandle, CURLOPT_URL, $soapUrl);
curl_setopt($cURLHandle, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($cURLHandle, CURLOPT_TIMEOUT, self::$connectorTimeout);
curl_setopt($cURLHandle, CURLOPT_SSL_VERIFYPEER, TRUE);
curl_setopt($cURLHandle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_NONE);
curl_setopt($cURLHandle, CURLOPT_HTTPHEADER, $headers);
curl_setopt($cURLHandle, CURLOPT_POST, 1);
curl_setopt($cURLHandle, CURLOPT_POSTFIELDS, $content);
curl_setopt($cURLHandle, CURLOPT_HEADER, false);
curl_setopt($cURLHandle, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
$responseXML = curl_exec($cURLHandle);
if(curl_exec($cURLHandle) === false)
{
echo 'Curl error: ' . curl_error($ch);
}
else
{
echo "no error <br />";
var_dump($responseXML);
}
I tried to see the error but get following i.e.
no error
I am stuck and researched over the internet and couldn't find anything on it therefore, is posting over here...
More Information:
When I tried this from command line i.e.
curl -H "Authorization: Bearer" https://dev2013.crm.example.com/XRMServices/2011/Discovery.svc -v
Then, I got the following output i.e.
About to connect() to dev2013.crm.appserv.co.nz port 443 (#0)
* Trying x.x.x.x... connected
* successfully set certificate verify locations:
* CAfile: none
CApath: /etc/ssl/certs
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using AES128-SHA
* Server certificate:
* subject: C=AU; ST=Sydney; L=Sydney; O=Example Ltd; CN=*.crm.example.com
* start date: 2015-06-24 00:00:00 GMT
* expire date: 2017-08-22 23:59:59 GMT
* subjectAltName: dev2013.crm.example.com matched
* issuer: C=US; O=thawte, Inc.; CN=thawte SSL CA - G2
* SSL certificate verify ok.
> GET /XRMServices/2011/Discovery.svc HTTP/1.1
> User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
> Host: dev2013.crm.example.com
> Accept: */*
> Authorization: Bearer
>
< HTTP/1.1 200 OK
< Connection: Keep-Alive
< Set-Cookie: ISAWPLB{11FDD9E3-24F0-455D-8590-436AF3F4D26D}={B0F3D377-6B32-45C6-A517-DA83209E8EA4}; HttpOnly; Path=/
< Content-Length: 3127
< Date: Thu, 16 Jul 2015 03:26:39 GMT
< Content-Type: text/html; charset=UTF-8
< Server: Microsoft-IIS/8.5
< Cache-Control: private
< X-AspNet-Version: 4.0.30319
< REQ_ID: 5b87d8d2-8b5e-4979-b090-7df14a3a1603
< Set-Cookie: ReqClientId=751fb9c2-ac10-478a-b933-2117420c660c; expires=Thu, 16-Jul-2065 03:26:39 GMT; path=/; secure; HttpOnly
< X-Powered-By: ASP.NET
It means that there is no issue with connecting to CRM using the above discovery server.
Looking for instant help on the error and the best recommendation to get authentication from the CRM using PHP SOAP webservices.
Thanks in advance.
Cheers,
Jason Lattimer has an updated example using IFD.
http://jlattimer.blogspot.com.au/2015/02/soap-only-authentication-using-php.html
At a glance there seems to be a few discrepancies.
Firstly you don't have a message ID (Should be just under the action line)
<a:MessageID>urn:uuid:{A RANDOM GUID GOES HERE}</a:MessageID>
Secondly you have the following line
<o:UsernameToken u:Id="user">
Which I walso believe should be a GUID
<o:UsernameToken u:Id="{GUID GOES HERE}">
Finally you look like you're pointing to the Discovery Service where I think you should be pointing to the organisation service.
Organization.svc
I haven't done any PHP-IFD stuff myself so I'd suggest going to Jason's blog and comparing it with yours.
Campey, thanks for your time. Both DEV and LIVE Servers are in the same timezone the only difference that I have found the DEV server timezone is 10 minutes behind from the LIVE server.
I corrected the time on DEV server and then the authentication problem is solved.
Thanks everyone for investing time to read the issue.
Related
I tried replicating a working curl command from CLI to a corresponding command via PHP and expected the same result. Instead I got a 400 bad request when doing the request via PHP.
I'm making a request for a Oath2 token via an API that requires you to use a certificate on all requests. The request works when I perform it with curl via CLI but when I try via PHP I get a 400 bad request response from the API.
This request with curl via CLI works.
curl --request POST \
--url https://sysorgoauth2.test.XXX.TLD/oauth2/v1/sysorg/token \
--cert /app/keys/eid.crt.pem \
--key /app/keys/eid.key.pem \
--header "Content-Type: application/x-www-form-urlencoded" \
--verbose \
-d "grant_type=client_credentials&client_id=<ID>&client_secret=<SECRET>&scope=<SCOPE>"
This request with curl via PHP does not work.
$headers = [
'User-Agent: curl/7.74.0 via PHP',
'Content-Type: application/x-www-form-urlencoded',
'Accept: */*',
];
$url = 'https://sysorgoauth2.test.XXX.TLD/oauth2/v1/sysorg/token';
$data = [
'grant_type' => 'client_credentials',
'client_id' => '<ID>',
'client_secret' => '<SECRET>',
'scope' => '<SCOPE>',
];
$body = http_build_query($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSLCERT, '/app/keys/eid.crt.pem');
curl_setopt($ch, CURLOPT_SSLKEY, '/app/keys/eid.key.pem');
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// For debug.
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
$stream = fopen('/tmp/curl_debug.txt', 'w+');
curl_setopt($ch, CURLOPT_STDERR, $stream);
$response = curl_exec($ch);
curl_close($ch);
This is the output from curl via PHP:
* Trying (IP redacted):443...
* Connected to sysoauth2.test.XXX.TLD (IP redacted) port 443 (#0)
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
* CApath: /etc/ssl/certs
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server did not agree to a protocol
* Server certificate:
* subject: C=X; ST=X; L=X; O=X; CN=sysoauth2.test.XXX.TLD
* start date: May 20 00:00:00 2022 GMT
* expire date: Jun 20 23:59:59 2023 GMT
* subjectAltName: host "sysoauth2.test.XXX.TLD" matched cert's "sysoauth2.test.XXX.TLD"
* issuer: C=US; O=DigiCert Inc; CN=DigiCert TLS RSA SHA256 2020 CA1
* SSL certificate verify ok.
> POST /oauth2/v1/sys/token HTTP/1.1
Host: sysoauth2.test.XXX.TLD
User-Agent: curl/7.74.0
Content-Type: application/x-www-form-urlencoded
Accept: */*
Content-Length: 187
* upload completely sent off: 187 out of 187 bytes
* Mark bundle as not supporting multiuse
< HTTP/1.1 400 Bad Request
< Content-Length: 172
< Content-Type: application/json; charset=UTF-8
< Cache-Control: no-store
< Pragma: no-cache
< Connection: Close
<
* Closing connection 0
This is the output from curl via CLI:
* Trying (IP redacted):443...
* Connected to sysorgoauth2.test.XXX.TLD (IP redacted) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
* CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Request CERT (13):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Certificate (11):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS handshake, CERT verify (15):
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server did not agree to a protocol
* Server certificate:
* subject: C=X; ST=X; L=X; O=X; CN=sysorgoauth2.test.XXX.TLD
* start date: May 20 00:00:00 2022 GMT
* expire date: Jun 20 23:59:59 2023 GMT
* subjectAltName: host "sysorgoauth2.test.XXX.TLD" matched cert's "sysorgoauth2.test.XXX.TLD"
* issuer: C=US; O=DigiCert Inc; CN=DigiCert TLS RSA SHA256 2020 CA1
* SSL certificate verify ok.
> POST /oauth2/v1/sysorg/token HTTP/1.1
> Host: sysorgoauth2.test.XXX.TLD
> User-Agent: curl/7.74.0
> Accept: */*
> Content-Type: application/x-www-form-urlencoded
> Content-Length: 187
>
* upload completely sent off: 187 out of 187 bytes
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Content-Length: 161
< Content-Type: application/json; charset=UTF-8
< Cache-Control: no-store
< Pragma: no-cache
< Connection: Close
<
{
"access_token":"<ACCESS_TOKEN>",
"expires_in":3600,
"token_type":"Bearer",
"scope":"<SCOPE>"
}
* Closing connection 0
The part that differs between the two are:
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Request CERT (13):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Certificate (11):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS handshake, CERT verify (15):
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS handshake, Finished (20):
I have tried all kinds of curl options in PHP to get this working. Perhaps CURLOPT_SSLCERT and CURLOPT_SSLKEY does not correspond to --cert and --key?
Any help would be much appreciated.
UPDATE 1
I captured the requests for both CLI and PHP with Wireshark and there is a difference in the end of the sequence, TCP Retransmission. Not sure what that means. Will investigate.
Wireshark CLI capture
Wireshark PHP capture
Wireshark PHP capture 2
UPDATE 2
Running the PHP code outside of my Docker environment does not produce the error. So this is somehow related to my dev environment.
Initially I was having issues trying to figure out why php curl under browser behaves differently when I tried to execute the same script by CLI.
By turning on the CURLOPT_VERBOSE with log output and compare the result of the CLI and browser, here are the differences I've seen:
CURL Under CLI
* About to connect() to proxy localhost port 3128 (#4)
* Trying ::1...
* Connection refused
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 3128 (#4)
* Establish HTTP proxy tunnel to someurl.com:443
* Server auth using Basic with user 'some_username'
> CONNECT someurl.com:443 HTTP/1.1
Host: someurl.com:443
Proxy-Connection: Keep-Alive
< HTTP/1.1 407 Proxy Authentication Required
< Mime-Version: 1.0
< Date: Fri, 11 Dec 2020 12:04:46 CST
< Via: 1.1 someotherurl.com:8080 (Cisco-WSA/12.0.1-334)
< Content-Type: text/html
< Connection: close
< Proxy-Connection: close
< Content-Length: 2109
< X-RBT-SCAR: 2.3.4.5:11517381:2000
< Proxy-Authenticate: Basic realm="Cntlm for parent"
* Authentication problem. Ignoring this.
<
* Received HTTP code 407 from proxy after CONNECT
* Connection #4 to host localhost left intact
CURL Under Browser
* About to connect() to someurl.com port 443 (#6)
* Trying 1.2.3.4...
* Connected to someurl.com (1.2.3.4) port 443 (#6)
* warning: ignoring value of ssl.verifyhost
* skipping SSL peer certificate verification
* SSL connection using TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
* Server certificate:
* subject: C=US,ST=FL,L=Boca Raton,O=Telit IoT Platforms,OU=secureWISE,CN=someurl.com
* start date: Apr 15 21:18:15 2020 GMT
* expire date: May 15 21:18:15 2022 GMT
* common name: someurl.com
* issuer: E=support#securewise.net,CN=secureWISE CA-256,OU=SecureWISE Certificate Authority,O=ILS Technology LLC,O=Telit Wireless Solutions Inc,L=Boca Raton,ST=Florida,C=US
* Server auth using Basic with user 'some_username'
> GET /someurl HTTP/1.1
Authorization: Basic SomeAuthKey
Host: someurl.com
Accept: */*
< HTTP/1.1 200 OK
< Date: Fri, 11 Dec 2020 04:07:40 GMT
< Server: Apache-Coyote/1.1
< X-Powered-By: Undertow/1
< Set-Cookie: JSESSIONID=c2BBPwZBjGxCaH5om6unoKaI; path=/
< Set-Cookie: somekey=somevalue; path=/
< Content-Type: text/xml
< Content-Length: 125291
< Content-disposition: attachment; filename=somefilename.xml
< Vary: Accept-Encoding,User-Agent
< SWOrigin: sw_proxy
< Connection: close
<
* Closing connection 6
My initial hunch is that this has something to do with proxy (as this PC does use a proxy to go online)
And looking at the browser log, it seems as if proxy was skipped.
I've also checked the phpinfo() for both the browser and CLI, and I can see that there's proxy, http_proxy, https_proxy defined in the environment variables, as well as under $_SERVER for CLI, but not on browser, which makes me believe more that my assumption is correct.
So in order to combat this, I've tried adding the following code before the curl call:
if(isset($_SERVER['http_proxy']))
unset($_SERVER['http_proxy']);
if (isset($_SERVER['https_proxy']))
unset($_SERVER['https_proxy']);
if (isset($_SERVER['proxy']))
unset($_SERVER['proxy']);
if(isset($_ENV['http_proxy']))
unset($_ENV['http_proxy']);
if (isset($_ENV['https_proxy']))
unset($_ENV['https_proxy']);
if (isset($_ENV['proxy']))
unset($_ENV['proxy']);
curl_setopt($ch, CURLOPT_URL, $target_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, "someuser:somepass");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_VERBOSE, true);
$result = curl_exec($ch);
curl_close($ch);
But the verbose still shows that it still tries to go through the proxy when executed under CLI.
Any suggestion on this?
After digging around, it turns out all I had to do was to by pass the someurl.com in the /etc/cntlm.conf by including the url in the NoProxy config.
EDIT:
I need a way to consume a SOAP service using PHP.
curl -vvvv -k -s -X POST --header 'Content-type: text/xml;charset="utf-8"' --header 'SOAPAction: vend' -u 'USER':'PIN' -d "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Header/><soapenv:Body><vend xmlns=\"http://host.vim.services.co.uk/xsd\"><sequence>6922343</sequence><origMsisdn>xxxxxxxxxxxxx </origMsisdn><destMsisdn>xxxxxxxxxxxxx</destMsisdn><amount>1000</amount><tariffTypeId>1</tariffTypeId></vend></soapenv:Body></soapenv:Envelope>" https://xxx.xxx.x.xxx:443/modlue/services/TargetOne ; echo;
Already, I have this piece of curl request (above), which gives me a successful response as shown below.
* Trying xxx.xxx.x.xxx...
* TCP_NODELAY set
* Connected to xxx.xxx.x.xxx (xxx.xxx.x.xxx) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server did not agree to a protocol
* Server certificate:
* subject: CN=*.xxx.xxxxxxe.com
* start date: Sep 10 00:00:00 2018 GMT
* expire date: Nov 28 12:00:00 2020 GMT
* issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=RapidSSL RSA CA 2018
* SSL certificate verify ok.
* Server auth using Basic with user 'username'
> POST /axis2/services/HostIFService HTTP/1.1
> Host: xxx.xxx.x.xxx
> Authorization: Basic V4mp00vKL2wb3LL6Z2hZZSIzI2RzCL2kbNPlQjExMQ==
> User-Agent: curl/7.58.0
> Accept: */*
> Content-type: text/xml;charset="utf-8"
> SOAPAction: vend
> Content-Length: 409
>
* upload completely sent off: 409 out of 409 bytes
< HTTP/1.1 200
< Content-Type: text/xml;charset=UTF-8
< Content-Length: 568
< Date: Wed, 15 Jan 2020 14:24:53 GMT
< Vary: Accept-Encoding
<
* Connection #0 to host xxx.xxx.x.xxx left intact
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><xsd:vendResponse xmlns:xsd="http://xxxxxx.xxx.xxxxx.xx.xx/xxx"><xsd:sequence>0000000001</xsd:sequence><xsd:statusId>301</xsd:statusId><xsd:txRefId>2020011515245375604706230</xsd:txRefId><xsd:origBalance>0.00</xsd:origBalance><xsd:origMsisdn>12345678910112 </xsd:origMsisdn><xsd:destMsisdn>12345678910112</xsd:destMsisdn><xsd:responseCode>0</xsd:responseCode><xsd:responseMessage>Insufficient Airtime</xsd:responseMessage></xsd:vendResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
However, I want to be able to transform the curl request into a proper PHP class (using either SoapClient or any other library) so that I can be able to extract the response for use in my application.
QUESTION
How can I achieve this using PHP?
WHAT I HAVE TRIED
I have tried the code below from NuSoap library and have also tried to follow the answer from this question but keep getting this Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from ....
SoapClient is enabled in my apache server.
$params = array(
"param" => "value"
);
$soap_client = new nusoap_client($wsdl_url, true);
$soap_client->setCredentials(USER_SERVICE, PASS_SERVICE, 'basic');
$soap_client->soap_defencoding = 'UTF-8'; //Fix encode erro, if you need
$soap_return = $soap_client->call("method_name", $params);
MORE INFORMATION
Below is a sample WSDL request and corresponding response
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://host.vim.services.co.uk/xsd">
<soapenv:Header/>
<soapenv:Body>
<xsd:vend>
<xsd:origMsisdn>2349062058470</xsd:origMsisdn>
<xsd:destMsisdn>09062058617</xsd:destMsisdn>
<xsd:amount>100</xsd:amount>
<xsd:sequence>138</xsd:sequence>
<xsd:tariffTypeId>1</xsd:tariffTypeId>
<xsd:serviceproviderId>1</xsd:serviceproviderId>
</xsd:vend>
</soapenv:Body>
</soapenv:Envelope>
NB: The request should contain a header field of the form Authorization: Basic , where credentials are the base64 encoding of id and password joined by a colon.
Below are the applicable client context object properties.
Authorization Data : MjM0OTAwMDAwMTIzNC9oYW5kc2V0OjU1MjY=
charset : UTF-8
content-type : application/xml
SoapAction : urn:Vend
And finally, here is the response to the request
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<vendResponse>
<destBalance>998860.0</destBalance>
<destMsisdn>09062058617</destMsisdn>
<origBalance>999360.0</origBalance>
<origMsisdn>2349062058470</origMsisdn>
<responseCode>0</responseCode>
<responseMessage>Successful</responseMessage>
<sequence>139</sequence>
<statusId>0</statusId>
<txRefId>2018122611455497901000006</txRefId>
<voucherPIN>40692125281574</voucherPIN>
<voucherSerial>600000000001</voucherSerial>
</vendResponse>
</soapenv:Body>
I am working on downloading ZIP from URL, and I have a problem with this. First step of my algorithm is to check what is the Content-Type and Content-Length of given url:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.dropbox.com/s/0hvgw7nvbdnh13d/ColaClassic.zip");
curl_setopt($ch, CURLOPT_HEADER, 1); //I
curl_setopt($ch, CURLOPT_NOBODY, 1); //without body
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); //L
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_exec($ch);
$content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
However, value of variable $content-type is text/html; charset=utf-8
Then I checked Content-Type from command line like this:
curl -IL https://www.dropbox.com/s/0hvgw7nvbdnh13d/ColaClassic.zip
and I got correct result (application/zip).
So, what is the difference between these two codes, and how do I get correct Content-Type in my php script?
Edit:
curl_setopt($ch, CURLOPT_URL, 'https://www.dropbox.com/s/0hvgw7nvbdnh13d/ColaClassic.zip');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD');
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_STDERR, $verbose);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
Verbose output from php curl:
* Hostname was found in DNS cache
* Hostname in DNS cache was stale, zapped
* Trying 162.125.69.1...
* Connected to www.dropbox.com (162.125.69.1) port 443 (#14)
* successfully set certificate verify locations:
* CAfile: none
CApath: /etc/ssl/certs
* SSL connection using ECDHE-RSA-AES128-GCM-SHA256
* Server certificate:
* subject: businessCategory=Private Organization; 1.3.6.1.4.1.311.60.2.1.3=US; 1.3.6.1.4.1.311.60.2.1.2=Delaware; serialNumber=4348296; C=US; ST=California; L=San Francisco; O=Dropbox, Inc; CN=www.dropbox.com
* start date: 2017-11-14 00:00:00 GMT
* expire date: 2020-02-11 12:00:00 GMT
* subjectAltName: www.dropbox.com matched
* issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=DigiCert SHA2 Extended Validation Server CA
* SSL certificate verify ok.
> HEAD /s/0hvgw7nvbdnh13d/ColaClassic.zip HTTP/1.1
Host: www.dropbox.com
Accept: */*
Verbose output from cmdline curl:
* Trying 162.125.69.1...
* TCP_NODELAY set
* Connected to www.dropbox.com (162.125.69.1) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:#STRENGTH
* successfully set certificate verify locations:
* CAfile: /etc/ssl/cert.pem
CApath: none
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-CHACHA20-POLY1305
* ALPN, server accepted to use h2
* Server certificate:
* subject: businessCategory=Private Organization; jurisdictionCountryName=US; jurisdictionStateOrProvinceName=Delaware; serialNumber=4348296; C=US; ST=California; L=San Francisco; O=Dropbox, Inc; CN=www.dropbox.com
* start date: Nov 14 00:00:00 2017 GMT
* expire date: Feb 11 12:00:00 2020 GMT
* subjectAltName: host "www.dropbox.com" matched cert's "www.dropbox.com"
* issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=DigiCert SHA2 Extended Validation Server CA
* SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x7fd8c4007a00)
> HEAD /s/0hvgw7nvbdnh13d/ColaClassic.zip HTTP/2
> Host: www.dropbox.com
> User-Agent: curl/7.54.0
> Accept: */*
Seems dropbox is issuing a different response code depending on user agent — or rather lack thereof. Your command line operation sends something like curl/7.47.0 (or your version) while the php script sends an empty user agent. Adding the user agent to your php request will get dropbox to respond appropriately with a HTTP/1.1 301 Moved Permanently response and then your script will follow the location on as expected:
$ch = curl_init();
// emulates user agent from command line.
$user_agent = 'curl/' . curl_version()['version'];
curl_setopt($ch, CURLOPT_URL, "https://www.dropbox.com/s/0hvgw7nvbdnh13d/ColaClassic.zip");
curl_setopt($ch, CURLOPT_HEADER, 1); //I
curl_setopt($ch, CURLOPT_NOBODY, 1); //without body
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); //L
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_exec($ch);
$content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
echo $content_type;
UPDATE: Oddly, I just tried a few other things, like emulating various browser useragent strings and it seems dropbox only seems to issue a redirect when presented with the curl/X.X.X useragent. ¯\_(ツ)_/¯
I apologize if the title is inappropriate, but I kind of could not think of a better definition for it.
I am going nuts over this problem. I have been working on collecting feeds and data via cURL for the past 5+ years and have never encountered this kind of situation. I have a large json to collect over the GET method from a remote server via HTTPS from address that looks something like this
https://private.example.com/thisDotNetEndPoint?token=bla-bla-trutj&someParam=1
someParam is changeable, and for some values with lower amount of data everything works fine, almost identical speeds to browser, but in several cases cURL always goes to tiomeout set, while in browser and from console everything works fine
PHP
My cURL is as follows:
$ch = curl_init();
$url = 'https://private.example.com/thisDotNetEndPoint?token=bla-bla-trutj&someParam=1';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
// I've added this user agent as it is the same as the one Chrome uses
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36');
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
// I have tried removing the SSL part below, but no difference
curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, "HIGH:!SSLv3s");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // tried this with true, but no difference
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 1200); // what ever the timeout I set the cURL always goes to timeout
curl_setopt($ch, CURLOPT_VERBOSE, true);
$response = curl_exec($ch);
if (curl_errno($ch)) {
print("cURL error: " . curl_error($ch));
print_r(curl_getinfo($ch));
} else {
print_r(json_decode($response));
}
curl_close($ch);
This is the verbose output:
* Hostname was NOT found in DNS cache
* Trying 12.34.567.89...
* Connected to private.example.com (12.34.567.89) port 443 (#0)
* successfully set certificate verify locations:
* CAfile: none
CApath: /etc/ssl/certs
* SSL connection using ECDHE-RSA-AES256-SHA384
* Server certificate:
* subject: OU=Domain Control Validated; CN=*.example.com
* start date: 2016-03-03 09:41:38 GMT
* expire date: 2018-03-04 09:52:18 GMT
* subjectAltName: private.example.com matched
* issuer: C=US; ST=Arizona; L=Scottsdale; O=Starfield Technologies, Inc.; OU=http://certs.starfieldtech.com/repository/; CN=Starfield Secure Certificate Authority - G2
* SSL certificate verify ok.
> GET /thisDotNetEndPoint?token=bla-bla-trutj&someParam=1 HTTP/1.1
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36
Host: private.example.com
Accept: */* */
* Operation timed out after 1200001 milliseconds with 0 bytes received
* Closing connection 0
It always goes to timout whatever the timout I set, tried even setting it to 2 hours.
I've even tried adding these but no difference:
curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
curl_setopt($ch, CURLOPT_LOW_SPEED_LIMIT, 1);
curl_setopt($ch, CURLOPT_LOW_SPEED_TIME, 1200);
Browser
When I enter the same url in browser the response comes back in 6-9 minutes
cURL from console
I have used the simplest command and it works in same time as browser:
$ curl -X GET -v 'https://private.example.com/thisDotNetEndPoint?token=bla-bla-trutj&someParam=1'
Verbose output:
* Hostname was NOT found in DNS cache
* Trying 12.34.567.89...
* Connected to private.example.com (12.34.567.89) port 443 (#0)
* successfully set certificate verify locations:
* CAfile: none
CApath: /etc/ssl/certs
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server key exchange (12):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using ECDHE-RSA-AES256-SHA384
* Server certificate:
* subject: OU=Domain Control Validated; CN=*.example.com
* start date: 2016-03-03 09:41:38 GMT
* expire date: 2018-03-04 09:52:18 GMT
* subjectAltName: private.example.com matched
* issuer: C=US; ST=Arizona; L=Scottsdale; O=Starfield Technologies, Inc.; OU=http://certs.starfieldtech.com/repository/; CN=Starfield Secure Certificate Authority - G2
* SSL certificate verify ok.
> GET /thisDotNetEndPoint?token=bla-bla-trutj&someParam=1 HTTP/1.1
> User-Agent: curl/7.35.0
> Host: private.example.com
> Accept: */* */
>
< HTTP/1.1 200 OK
< Cache-Control: private
< Content-Type: application/json; charset=utf-8
< Server: Microsoft-IIS/8.5
< X-StackifyID: V1|b8b10c35-2649-4f67-ba6a-b5ad15ef553b|C56050|CD18|
< Set-Cookie: .ASPXANONYMOUS=looI88UVBp6Cg5tLkzVejO4CNRilhyKjMY4hFqhuO48vdVT19U8h5oisC9khFv1rOmH6Ii_lEec-9XhipEvh1UkewhufqfmlTGFsyQCaML06NVa-5-Vr_OikZb07R6pdHCeRtn9liBVJfamJmXiElA2; expires=Thu, 02-Feb-2017 20:54:18 GMT; path=/; HttpOnly
< X-AspNetMvc-Version: 5.2
< Rx-CID: ae9907d6fc394b24b6599e74ab5a668f
< Rx_RequestId: f3fff82c4de04bba90b2bbc5704ac787
< X-Powered-By: ASP.NET
< Strict-Transport-Security: max-age=31536000
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Headers: rx-cid
< Date: Fri, 25 Nov 2016 10:25:00 GMT
< Content-Length: 2231472
<
[and the response is printed here]
Any ideas?
Thanks in advance.
Did you notice the difference between the console and your php verbose output? The useragent is missing in your php code. curl commandline by default adds this useragent, whereas the php-curl doesn't.
User-Agent: curl/7.35.0
Use the option CURLOPT_USERAGENT.
curl_setopt($ch, CURLOPT_USERAGENT, "Opera 11.0");