Curl failed: Couldn’t resolve host ‘android.googleapis.com” - php

Please find below error messages. I got those when I tried to send GCM push notifications from curl command line on my computer. What is wrong with this command?
Command Line:
curl --header "Authorization: key=AIzaSyDq5WEWwiKCcDotArJXJUY6gX2AEDcxArM" --header Content-Type:"application/json" https://android.googleapis.com/gcm/send -d "{\"registration_ids\":[\"f_0-7BAEtbc:APA91bFjLUj6cMB6n_Vz070CeaAiIpMgP3HvaS9HeptE2SMd7HMyjCDmKpmjMpODoHdezJm62WWScYp2qIt4wfIVv1xBubdYb61jleIpLlx69X2u5j1nBiJHVc3kU8fc6VGAq_dIbBZz\"]}"
Result:
Curl failed: Couldn’t resolve host ‘android.googleapis.com”.
The best regards
Doeun KOCH

Related

Microsoft-Cognitive Text Translation API

AZURE - The official documentation and examples for PHP is not working, help?
I am using the code at this link:
https://github.com/courtney7/HTTP-Code-Samples/blob/37a4431f75397e1ccc6ee3f62ef14b3909a2dc85/PHP/PHPAzureToken.php
Always test and debug APIs using curl (i.e. take a curl first approach). Here's an example that works on my Windows 10 system. Here's the curl that gets a token.
curl -k --data "" "https://api.cognitive.microsoft.com/sts/v1.0/issueToken" -H "Ocp-Apim-Subscription-Key:<your Ocp-Apim-Subscription-Key>"
Example to get token and call text translate.
curl -k --data "" "https://api.cognitive.microsoft.com/sts/v1.0/issueToken" -H "Ocp-Apim-Subscription-Key:<your Ocp-Apim-Subscription-Key>" > Bearer.txt
set /p Bearer= < Bearer.txt
curl -H "Authorization: Bearer %Bearer%" "https://api.microsofttranslator.com/v2/Http.svc/Translate?Text=Hello+world.&From=en&To=es"
Make sure you are calling the correct endpoint "https://api.cognitive.microsoft.com/sts/v1.0/issueToken"

Command works in cmd prompt but not in Powershell, what am I doing wrong?

So I've been tearing my hair out all day regarding this one. I have a curl command which I have working on a windows machine which pulls logs from Cloudflare, this works.
curl -sv -o logname.log.gz -X GET -H "Accept-encoding: gzip" -H "X-Auth-Email: myemail#email.com" -H "X-Auth-Key: 12345" "https://api.cloudflare.com/client/v4/zones/987654/logs/requests?start=1481509909&end=1481538709"
I'm trying to import this into powershell with the end goal of making the start and end time parameters different based on the current time, however I simply cannot get the command to run in powershell, I've tried various different tracks with this being the latest and most simple.
cmd.exe /c 'curl -sv -o logname.log.gz -X GET -H "Accept-encoding: gzip" -H "X-Auth-Email: myemail#email.com" -H "X-Auth-Key: 12345" "https://api.cloudflare.com/client/v4/zones/987654/logs/requests?start=1481509909&end=1481538709"'
Which gives me this error
{ [11971 bytes data]
* Failed writing body (0 != 11963)
* Failed writing data
* Curl_http_done: called premature == 1
* Closing connection 0
* schannel: shutting down SSL/TLS connection with api.cloudflare.com port 443
* schannel: clear security context handle
I already know that my unix timestamp is a bit off and plan on fixing that next but what I cannot understand is why the same command works through the command prompt and not through Powershell.
Would someone be able to help?
Thank you
Dealing with parameters to native commands in PowerShell can be a minefield because you have to deal with quoting and special characters for both, sometimes nested.
It's probably safer to use Start-Process in PowerShell and give it an array of parameters:
Start-Process curl.exe -ArgumentList '-sv','-o','logname.log.gz','-X','GET','-H','Accept-encoding: gzip','-H','X-Auth-Email:','myemail#email.com','-H','X-Auth-Key:','12345','https://api.cloudflare.com/client/v4/zones/987654/logs/requests?start=1481509909&end=1481538709'
But what you should realy do, is check out Invoke-WebRequest which will ultimately be much easier.
$body = #{
start = 1481509909
end = 1481538709
}
$headers = #{
'Accept-Encoding' = 'gzip'
'X-Auth-Email' = 'myemail#email.com'
'X-Auth-Key' = '12345'
}
$response = Invoke-WebRequest -Uri 'https://api.cloudflare.com/client/v4/zones/987654/logs/requests' -OutFile logname.log.gz -Body $body -Headers $headers
Note this is not tested at all, but should be a good starting point.

cURL works great in terminal but dies with 500 error in script

I have a problem similar to the one described here, though the suggested solution does not work for me:
PHP CURL GET request returns 500 where bash curl succeeds
The suggested solution was:
"It turns out that the API I was accessing required a User-Agent for all requests, but did not provide any information to indicate such."
Which didn't work for me.
If I open a terminal window and do this:
curl "http://needi.local:8080/search/uber" -X GET --header 'Accept: application/json' --header 'x-api-key: 2gt7Pt2LU194KKcNnc'
I get all the results that I expect. It works great.
If I create this PHP file:
<?php
$command = "curl 'http://needi.local:8080/search/uber' -X GET --header 'Accept: application/json' --header 'x-api-key: 2gt7Pt2LU194KKcNnc'
echo passthru($command);
This gets me:
php -f tests/functional/curl_external_api_tests.php
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 109 100 109 0 0 2893 0 --:--:-- --:--:-- --:--:-- 2945
{
"statusCode": 500,
"error": "Internal Server Error",
"message": "An internal server error occurred"
}
Adding the user agent does not fix the problem:
$command = "curl 'http://needi.local:8080/search/uber' -X GET --header 'Accept: application/json' --header 'x-api-key: 2gt7Pt2LU194KKcNnc' --header 'User-Agent: PHP-test/1.0'
What else could the problem be?
[ UPDATE: ]
I am sorry if anyone thought this was a question about PHP. I should rephrase as "what might be different in a script, relative to what I do in the terminal?" I also tried to use bash and I got the same error. But the cURL works in the terminal. So what changes when I leave the terminal and instead use bash or PHP or anything else?
I suspect your arguments to curl are getting truncated and so curl never passes the header. Do try using escapeshellarg and see if it helps.
In the end, I found a bug in the API app. So for anyone else who comes across this, I want to emphasize that my PHP worked great. I did get to the point where this worked:
<?php
$command = "curl 'http://needi.local:8080/search/uber' -X GET --header 'Accept: application/json' --header 'x-api-key: 2gt7Pt2LU194KKcNnc'
echo passthru($command);

Symfont REST curl: (7) Failed connect to localhost:8000; No error

I am learning Symfony REST using this tutorial I found here
http://voryx.net/rest-apis-with-symfony2-the-easy-way/
I have gotten to the point where have to make a PUT using this command on my project's root console
curl -i -H "Content-Type: application/json" -X POST -d '{"name" : "Test Post", "description" : "This is a test post"}' http://localhost:8000/app_dev.php/api/posts
When I execute this command above, I get this error on my console
curl: (3) [globbing] unmatched close brace/brac
curl: (7) Failed connect to localhost:8000; No error
Please assist me I am pushing myself to learn Symfony REST

INTERNAL_SERVICE_ERROR when trying to verify payment via paypal REST API

I'm trying to validate a payment made through a partner service. The partner is passing me the payment id and I'm using the REST API to look it up. So far, all attempts to use the payments/payment/<Payment-Id> are throwing an INTERNAL_SERVICE_ERROR. (I'm still using the sandbox and demo user.)
Getting a token seems to be working fine:
curl -v https://api.sandbox.paypal.com/v1/oauth2/token -H "Accept: application/json" -H "Accept-Language: en_US" -u "EOJ2S-Z6OoN_le_KS1d75wsZ6y0SFdVsY9183IvxFyZp:EClusMEUk8e9ihI7ZdVLF5cZ6y0SFdVsY9183IvxFyZp" -d "grant_type=client_credentials"
Response:
{"scope":"https://api.paypal.com/v1/developer/.* https://api.paypal.com/v1/payments/.* https://api.paypal.com/v1/vault/credit-card https://api.paypal.com/v1/vault/credit-card/.*","access_token":"A015GzttpnOSOPfcqtfAaq1kdgqow5W.IXSe6TJ9Cpbesr4","token_type":"Bearer","app_id":"APP-8KK24973T6066201W","expires_in":28800}
Taking that token and putting into the payment request:
curl -v -X GET https://api.sandbox.paypal.com/v1/payments/payment/PAY-8UD377151U702286RKOQ3DTQ -H "Content-Type:application/json" -H "Authorization: Bearer A015GzttpnOSOPfcqtfAaq1kdgqow5W.IXSe6TJ9Cpbesr4"
returns the error:
{"name":"INTERNAL_SERVICE_ERROR","message":"An internal service error has occurred","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#INTERNAL_SERVICE_ERROR","debug_id":"ca33c7679121d"}
UPDATE: basically I'm trying to follow the steps outlined here: https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/

Categories