I have an application that allows me to send as sms in a url using my android phone as follows:
http://196.96.53.25/sendsms? phone=0724206400&text=Yusuf_kiprop
however, when I remove the underscore from the text as follows:
http://196.96.53.25/sendsms?phone=0724206400&text=Yusuf kiprop
I get an error that webpage is unavailable. What could be the issue?
If you are sending from php then encode the message like
$message=urlencode('Yusuf kiprop');
http://196.96.53.25/sendsms?phone=0724206400&text=$message
If you are checking it in the browser directly its not being url encoded thats why.
Try this insted-:
http://196.96.53.25/sendsms?phone=0724206400&text=Yusuf%20kiprop
Related
I use file_get_contents to send a request to a web service, let say:
https://example.com/mywebservice?arg1=value1&arg2=value2
If value2 is avaluewith#sometextafter, I send:
https://example.com/mywebservice?arg1=value1&arg2=avaluewith#sometextafter
My problem is that when the web server processes the request, it gets arg2=avaluewith
The pound character and what is after is lost.
How to correct that?
THe URL's hash is never sent to the webserver. It exists solely client-side.
I added urlencode() to the param which was truncated and it works fine.
Now the full URL with full params is received and processed by the web service.
My question is related to Slack's Slash commands.
I am trying to echo response back to invoking channel.
e.g I have integerated a test command like
/test hello
and I want response as:
Hello
Wold
but I am currently getting it as (in my slack channel):
{"text":"hello\nworld"}
This is my PHP code:
$payload = '{"text":"hello\nworld"}';
echo $payload;
Note I don't want to just echo like this:
echo "hello\nworld";
Thanks in advance :)
Maybe useful in giving answer:-
Sample wrong response actual:
Slack slash command API url:
https://api.slack.com/slash-commands
If you had carefully read the docs (which you linked), you would have noticed that it says:
NOTE: If you are responding with JSON instead of plain text, the content-type header of the response must match the disposition of your content, application/json.
It looks like you're just outputting JSON without sending the correct Content-Type header, so Slack thinks it's plain text and displays your JSON as plain text.
Also, consider using json_encode instead of manually writing JSON.
I am trying to handle Mandrill's webhook data when I get a bounce I want Mandrill to tell my app which email it was and save various data in a MySql Database.
I am working with PHP here, according to Mandrill they send a URL I give them a $_POST request with JSON data.
Normally I would json_decode() this request, but when I do so, it appears to be blank. To me the JSON looks malformed, but perhaps I need to do something else with it first?
This is what I receive in my script:
[mandrill_events] =>
[{\"event\":\"hard_bounce\",\"msg\":{\"ts\":1365109999,\"subject\":\"This an example webhook message\",\"email\":\"example.webhook#mandrillapp.com\",\"sender\":\"example.sender#mandrillapp.com\",\"tags\":[\"webhook-example\"],\"state\":\"bounced\",\"metadata\":{\"user_id\":111},\"_id\":\"exampleaaaaaaaaaaaaaaaaaaaaaaaaa\",\"_version\":\"exampleaaaaaaaaaaaaaaa\",\"bounce_description\":\"bad_mailbox\",\"bgtools_code\":10,\"diag\":\"smtp;550 5.1.1 The email account that you tried to reach does not exist. Please try double-checking the recipient\'s email address for typos or unnecessary spaces.\"},\"_id\":\"exampleaaaaaaaaaaaaaaaaaaaaaaaaa\",\"ts\":1390483382},{\"event\":\"soft_bounce\",\"msg\":{\"ts\":1365109999,\"subject\":\"This an example webhook message\",\"email\":\"example.webhook#mandrillapp.com\",\"sender\":\"example.sender#mandrillapp.com\",\"tags\":[\"webhook-example\"],\"state\":\"soft-bounced\",\"metadata\":{\"user_id\":111},\"_id\":\"exampleaaaaaaaaaaaaaaaaaaaaaaaaa1\",\"_version\":\"exampleaaaaaaaaaaaaaaa\",\"bounce_description\":\"mailbox_full\",\"bgtools_code\":22,\"diag\":\"smtp;552 5.2.2 Over Quota\"},\"_id\":\"exampleaaaaaaaaaaaaaaaaaaaaaaaaa1\",\"ts\":1390483382}]
You have the magic_quotes option set in your server.
You can disable it, or simply remove the trailing slashes from the response and then do the json_decode:
$response = json_decode(stripslashes($_RESPONSE['mandrill_events']), true);
More information about stripslashes: http://php.net/manual/en/function.stripslashes.php
So, I have this method where I need to call an external url (different domain). It's something like http://192.168.2.2:9090/send?num=100&txt=text; Is there any way to do this without using curl?
I guess I should clarify that I have tried using curl with the yii-curl extension but somehow it doesn;t seem to work. It works when I supply a whole formatted url, but if I try to modify the url with params for num and txt, it doesn't work for some reason. Preferably I am looking for a solution without curl, but if that is not possible I could use some help with how to format and execute a proper url so I can also supply params to the url. Thanks.
Edit: I don't think file_get_contents() will work as the url is actually to an SMS gateway that sends sms. the phone number and sms text is supplied as params. Let me know if I am guessing it wrong.
Edit 2: This is what I tried after the suggestions here.
public function sendTXTSMS($sentToNum,$text)
{
$construct_url="http://192.168.2.2:9090/send?num={$sentToNum}&txt={$text}";
file_get_contents($construct_url);
}
And then calling it like,
$text='Lorem ipsum dolor ........ ';
$this->sendTXTSMS(XXXXXXXXXX,$text)
XXXXXXXXXX is of course the phone number masked here.
Now I am getting an HTTP request failed! HTTP/1.1 400 Bad Request error. allow_url_fopen is enabled and I can access the url fine by typing it on a browser. Also tried using urlencode on the url.
If it's a GET request you can use file_get_contents($url);.
If you need more options you can try the HTTP library, but there's little reason to not directly use libcurl. It's standard practice.
The fact it's connecting to a service related to SMS is irrelevant. If it's a URL for a web service on a server you can connect to, you can make a request to it.
file_get_contents() will work if allow_url_fopen is enabled in php.ini, but I think your problem is this:
It works when I supply a whole formatted url, but if I try to modify
the url with params for num and txt, it doesn't work for some reason.
You need to encode the data:
$test = urlencode($text);
$sentToNum = urlencode($sentToNum);
$construct_url = "http://192.168.2.2:9090/send?num={$sentToNum}&txt={$text}";
Yes you can use file_get_contents http://php.net/manual/en/function.file-get-contents.php
Using curl should be a better option since you can easily deal with http status code...
But with or without curl, you need to build your url correctly, urlencode should be used on params, not on url :
$sentToNum = urlencode($sentToNum);
$text = urlencode($text);
$construct_url="http://192.168.2.2:9090/send?num={$sentToNum}&txt={$text}";
I have to send some specific xml to a php script (from flash AS2) that then sends out sms message based on the xml. I have been given the xml by the sms sender and have tested it via their live demo and that works fine. The problem I am having is getting flash to send this XML.
The sms sender states that it needs to recieve the xml in the following format: The XML Document should be posted uriencoded, with a UTF‐8 character set as paramaeter 'xml'
Here is the code I have so far, I think something is missing maybe. I have tried running the swf in a browser rather than in the flash testing environment
var my_xml:XML = new XML('<xml></xml>');
my_xml.contentType = "text/xml";
send_btn.onRelease = function () {
my_xml.send("http://address-to-send-to.com" , "_blank");
};
Any ideas?
Try to use my_xml.sendAndLoad instead of my_xml.send that should return the xml back to your object.
Cheers