ActionScript POST - apache-flex

How to post data from a flex file to a php file? I am not able to create an action.

What you need is to create a URLRequest object where you set up your method and data to send. You then start the request with a Loader object.
var req:URLRequest = new URLRequest(yourURL);
req.method = URLRequestMethod.POST;
var vars:URLVariables = new URLVariables();
vars.yourVar = 'yourValue';
req.data = vars;
var ldr:Loader = new Loader();
ldr.load(req);

You need to create an HTTPService in order to send data to a server application like a PHP file from Flex. The data that is going to be sent could be an XML, that way in your PHP file you can parse that XML and get the information that is in it.
I use this function to transform my objects to XML and then send that XML in the HTTPService:
public function objectToXML(obj:Object, root:String):XML {
var qName:QName = new QName(root);
var xmlDocument:XMLDocument = new XMLDocument();
var simpleXMLEncoder:SimpleXMLEncoder = new SimpleXMLEncoder(xmlDocument);
var xmlNode:XMLNode = simpleXMLEncoder.encodeValue(obj, qName, xmlDocument);
var xml:XML = new XML(xmlDocument.toString());
return xml;
}
That way I create objects with normal properties and don't worry about how to create the XML, then when you are going to send the XML in the HTTPService you just call the method "objectToXML" on the send method of your HTTPService.
You do that like this:
var myData:Object=new Object();
myData.name="Information";
var myService:HTTPService = new HTTPService();
myService.url = "http://example.com/yourFile.php";
myService.method = "POST";
myService.contentType="application/xml";
myService.send(objectToXML(myData,"parent"));

Related

Asp.net core disable change string in Uri

I have a Encoded string like this:
https://xx.yyy.ir/xx/ff/addUser?name=%d8%b3%d9%84%d8%a7%d9%85
But when I use Uri to convert it to a URL and send it
result = "https://xx.yyy.ir/xx/ff/addUser?name=%d8%b3%d9%84%d8%a7%d9%85"
var client = new HttpClient
{
BaseAddress = new Uri(result.ToString()),
};
var response = await client.GetAsync("");
it send this request :
https://xx.yyy.ir/xx/ff/addUser?name=سلام
why this happen? how to prevent from this?
This is what's causing your problem: new Uri(result.ToString())
Let's try to do this in a proper manner and see what happens.
var builder = new UriBuilder("https://xx.yyy.ir/xx/ff/addUser") { Port = -1 };
var query = HttpUtility.ParseQueryString(builder.Query);
query["name"] = "سلام";
builder.Query = query.ToString();
using var httpClient = new HttpClient();
var response = await client.GetAsync(builder.ToString());
builder.ToString() returns https://xx.yyy.ir/xx/ff/addUser?name=%d8%b3%d9%84%d8%a7%d9%85
So basically, the above code boils down to this:
using var httpClient = new HttpClient();
var response = await client.GetAsync("https://xx.yyy.ir/xx/ff/addUser?name=%d8%b3%d9%84%d8%a7%d9%85");
Tested and verified on my computer.

Set HTTP body using HTTPService class in the Adobe Air

I need to send a byte array of data as a HTTP body using HTTPService class in the Adobe Air API. Can anyone suggest me the way of doing this?
Try this
var encodedString : String = Base64.encode( imageByteArray );
var service : HTTPService = new HTTPService();
service.method = "POST";
service.contentType = 'application/x-www-form-urlencoded';
service.url = 'http://www.mydomain.com/upload.php';
var variables : URLVariables = new URLVariables();
variables.imageArray = encodedString;
variables.variable2 = "some text string";
variables.variable3 = "some more text";
service.send( variables );
Base64 class get from
http://code.google.com/p/jpauclair-blog/source/browse/trunk/Experiment/Base64/src/Base64.as

form submission

How to specify action to button to submit a form in adobe adobe flex?
You can use the URLRequest and the Loader object.
Your function would look like this: submitForm():void {
var req:URLRequest = new URLRequest(yourURL);
req.method = URLRequestMethod.POST;
var vars:URLVariables = new URLVariables();
vars.yourVar = 'yourValue';
req.data = vars;
var ldr:Loader = new Loader();
ldr.load(req);
}
and your button would look something like this:
<mx:Button label="Submit" click="submitForm();"/>
See this page for more information.

PDF export to local using AlivePDF with flex

I need to export charts and data tables to pdf file in flex application.
For this we can user AlivePDF but i need to export to local not server.
Can we export to local system prompting user to select the location to export?
Thanks in advance.
Since FP10 the FileReference Class should support this via the save() function. The code to do this in Flash Player 10 or better is shown below:
var bytes:ByteArray = pdf.save(Method.LOCAL);
var file:FileReference = new FileReference();
file.save(bytes, "myPDF.pdf");
Try this
var pdfFile:PDF = new PDF();
var pdfByteArray:ByteArray = new ByteArray ();
pdfByteArray = pdfFile.save(Method.LOCAL);
With the latest version of AlivePDF (0.1.5 RC), you can do this:
var element:IBitmapDrawable; // Chart to export
var pdf:PDF = new UnicodePDF();
pdf.addPage();
var bitmapData:BitmapData = new BitmapData(element.width, element.height, false, 0xffffff);
try{
bitmapData.draw(element as IBitmapDrawable);
}catch(e:*)
{
throw new Error("bitmap draw failed");
}
var jpegencoder:JPEGEncoder = new JPEGEncoder(100);
var byteArray:ByteArray = jpegencoder.encode(bitmapData);
pdf.addImageStream(byteArray);
var file : FileReference = new FileReference()
file.save(pdf.save(Method.LOCAL),"my.pdf");

problem in getting value of the object attribute in flex

i have an xml which contains 'interface' sub tag, iam converting xml to object using SampleXmlDecoder. compiler did not allow me to access the value of the 'inteface' attrible of the resultobject.
var xml:XML = event.result as XML;
var xmlDoc : XMLDocument = new XMLDocument(xml.toString());
var decoder : SimpleXMLDecoder = new SimpleXMLDecoder(true)
var resultObj : Object = decoder.decodeXML(xmlDoc);
var o:Object = new Object();
o.someprop = resultObj.maintag.item.interface;
its treating interface as keyword.
can anyone tell me the solution for this. Thanks in advance
o.someprop = resultObj.maintag.item["interface"];

Resources