Send XML to php script from flash AS2 - php

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

Related

Sending a message through a url

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

Sending received original JSON via cURL

I just want a little help.
So this is the scenario:
I have a php script that received a JSON and get it by file_get_contents function.
The json is send by API more likely like Glabs.
So for example I'll text the given shortcode for the API and it will send in json format and I'll be receiving it via PHP.
My question is, how can i send the original json format that i've received via cURL?
and receive it again by file_get_contents?is it possible?
Here is my sample script:
$json = file_get_contents('php://input');
$json = stripslashes($json);
$values=json_decode($json,true);
$Msg=$values["inboundSMSMessageList"]["inboundSMSMessage"][0]["message"];
$dateTime=$values["inboundSMSMessageList"]["inboundSMSMessage"][0]["dateTime"];
$MPN=str_replace("tel:","",$values["inboundSMSMessageList"]["inboundSMSMessage"][0]["senderAddress"]);
That is my script for receiving a message sent from a mobile phone to a shortcode then received by my script.
Thanks for who will help me

cannot access ajax data sent on the server

I am following this tutorial to make an events calendar-it utilizes backbone and the fullcalendar jquery plugin.
Backbone is responsible for sending to the server(via ajax) event details(start date,end date,title).Here is an image of what is sent to the server.
It is taken by the network panel(headers tab) of Chrome Dev Tools. I would expect that with the following line of code I would access the title of the event:
$title=$conn->real_escape_string($_POST['title']);
But I cannot, I do not understand why this happens. backbone sends JSON to server via the POST method. What am I missing here?
PHP has a problem with parsing json data, because it expects the posted data to be in a Querystring format (key=value&key1=value1).try using this:
$content = file_get_contents("php://input");
You are sending a JSON dictionary in the request body. Use http_get_request_body in PHP to obtain the full JSON string, then json_decode it.

Problems doing ajax-requests with a Phonegap application

I'm trying to create a simple RSS reader with Phonegap and jQuery.
I am following this tutorial: http://visualrinse.com/2008/09/24/how-to-build-a-simple-rss-reader-with-jquery/.
I've managed to get this working just fine when I try out the code in my browser. The php-file fetches the feed and outputs it just like I expect it to. But when I run the same file from within my compiled Phonegap application the ajax-request just returns the contents of the php-file (the php-code, not the executed result).
I've spent hours Googling this and tried numerous tutorials and tweaks. I found no solutions in the offical Phonegap forums either. What am I doing wrong? The problem seems to be PHP not responding to the request. I've tried to move the php-file to a different domain but the result is the same, it works in my browser but not in the compiled app.
Here's the jQuery code that initiates the ajax-code:
function get_rss_feed() {
//clear the content in the div for the next feed.
$("#feed_content").empty().html('<img class="loader" src="js/images/ajax-loader.gif" alt=""/>');
$.ajax({
url: 'http://192.168.1.7/rssApp/www/rss-proxy.php?url=http://www.nytimes.com/services/xml/rss/nyt/GlobalHome.xml',
success: function parseRSS(d) {
//find each 'item' in the file and parse it
$(d).find('item').each(function() {
//name the current found item this for this particular loop run
var $item = $(this);
// grab the post title
var title = $item.find('title').text();
// grab the post's URL
var link = $item.find('link').text();
// next, the description
var description = $item.find('description').text();
//don't forget the pubdate
var pubDate = $item.find('pubDate').text();
// now create a var 'html' to store the markup we're using to output the feed to the browser window
var html = "<div class=\"entry\"><h2 class=\"postTitle\">" + title + "<\/h2>";
html += "<em class=\"date\">" + pubDate + "</em>";
html += "<p class=\"description\">" + description + "</p>";
html += "<a href=\"" + link + "\" target=\"_blank\">Read More >><\/a><\/div>";
//put that feed content on the screen!
$('#feed_content').append($(html));
});
$('#feed_content img.loader').fadeOut();
}
});
};
Here's the rss-proxy.php that loads the XML from the url and outputs it:
<?php
// PHP Proxy
// Loads a XML from any location. Used with Flash/Flex apps to bypass security restrictions
// Author: Paulo Fierro
// January 29, 2006
// usage: proxy.php?url=http://mysite.com/myxml.xml
$session = curl_init($_GET['url']); // Open the Curl session
curl_setopt($session, CURLOPT_HEADER, false); // Don't return HTTP headers
curl_setopt($session, CURLOPT_RETURNTRANSFER, true); // Do return the contents of the call
$xml = curl_exec($session); // Make the call
header("Content-Type: text/xml"); // Set the content type appropriately
echo $xml; // Spit out the xml
curl_close($session); // And close the session
?>
I've finally managed to solve this!
It turns out that you need to whitelist the server you wish to request from your PhoneGap application in Xcode if you want to do requests to a certain domain (be it your localhost or whatever).
The reason that I didn't found this out earlier was that I didn't check for errors in the ajax response. Once I did that I got the http status code 401 (Unauthorized) and error message "Whitelist rejected".
To fix this I opened the file PhoneGap.plist in my project and under the key ExternalHosts i added a new item with the value: *.localhost.
I also changed the ajax url to:
url: 'http://localhost/rssApp/www/rss-proxy.php?url=http://www.nytimes.com/services/xml/rss/nyt/GlobalHome.xml'
I compiled and run the application on the iOS Simulator and my localhost server responded with a perfectly successful ajax response!
For every external host that you wish your application to connect to you must add it to the list of ExternalHosts. For example if you wish to access an API on http://google.com/maps/api.php you must add *.google.com to your list.
Kind of annoying when you try to figure out why the server isn't responding, but I guess it's good for security reasons. Hope this helps someone else out there who's struggling with simple ajax requests from their PhoneGap application!
It looks like you are running your server locally (based on the 192.168.x.x IP address) which means that only devices connnected to your network can access it. You could connect the phone to the same wifi network as your computer as a temporary fix. But you're going to need to host this on a real server for it to be accessible over the internet.
You could also forward port 80 on your router to this IP address and then use your actual IP address (see whatsmyip.org) in your request url. But that's not a really stable solution.

sending xml file from php to an android application

I am trying to send an xml file as a httpresponse to a post from an android application.
I understood how to send data from a php page here.
Is it possible to send a xml file as a response?
Or do I have to send the content of xml file as a string and parse it in the application?
If it is possible, How do I read the file in my application, so that I can parse it for information?
Thank you.
Send the xml from the server as a string. And in the application side parse the string either using SaxParser, XmlPullParser or DomParser. These are all commonly used.
This is a tutorial from IBM which gives an overview of parsing in android
http://www.ibm.com/developerworks/opensource/library/x-android/index.html
Of course you can. just you can send the xml format type in a php source file.
like following code. sorry for writing [ instead of < or > as this post doesn't allow tag elements.
echo '[?xml version="1.0" encoding="utf-8"?]';
echo '[something][/something]';

Categories