Encoding query
Hi,
I want to write an app which allows someone to describe how to parse an incoming byte stream into a number of strings.
The user can describe the length of each string and how it's encoded. What I'm trying to figure out is - depending on the encoding, will the number of bytes vary for a particular string? For example, "Hello" will normally be 5 bytes but can it be encoded in such a way that involves more than 5 bytes?
Thanks for any help.
Surely the developer doesn't have to worry about this?
The description of InputStreamReader would seem to suggest that it takes care of converting non-unicode byte streams to unicode characters.
From http://java.sun.com/docs/books/tutorial/i18n/text/stream.html :
For example, to translate a text file in the UTF-8 encoding into Unicode, you create an InputStreamReader as follows:
FileInputStream fis = new FileInputStream("test.txt");
InputStreamReader isr = new InputStreamReader(fis, "UTF8");
Similar Messages
-
Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs. at Error$/throwError() at flash.net::URLVariables/decode() at flash.net::URLVariables() at flash.net::URLLoader/onComplete() _________________________________________________________________________________________ _____________________ stop(); var DepartVars:URLVariables = new URLVariables(); var DepartURL:URLRequest = new URLRequest("scripts/www.mywebsite.com/depart.php"); DepartURL.method = URLRequestMethod.POST; DepartURL.data = DepartVars; var DepartLoader:URLLoader = new URLLoader; DepartLoader.dataFormat = URLLoaderDataFormat.VARIABLES; DepartLoader.addEventListener(Event.COMPLETE, completeDepart); depart_btn.addEventListener(MouseEvent.CLICK, DepartUser); // Function to run when the Depart button is pressed function DepartUser (event:MouseEvent):void{ // Ready the variables here for sending to PHP DepartVars.post_code = "Depart"; // Send the data to the php file DepartLoader.load(DepartURL); welcome_txt.text = "Processing request...Bon Voyage"; } // Close DepartUser function /////////////////////////////////////// // Function for when the PHP file talks back to flash function completedepart(event:Event):void{ if (event.target.data.replyMsg == "success") { var refreshPage:URLRequest = new URLRequest("javascript:NewWindow=window.location.reload(); NewWindow.focus(); void(0);"); navigateToURL(refreshPage, "_self"); } // Close completeDepart function ////////////////////////////// // Code for the View res Button var viewRes:URLRequest = new URLRequest("view_res.php"); viewRES_btn.addEventListener(MouseEvent.CLICK, viewResClick); function viewResClick(event:MouseEvent):void { navigateToURL(viewRes, "_self"); } ///////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////// // Code for the Edit Res profile Button var editRes:URLRequest = new URLRequest("edit_res.php"); editRES_btn.addEventListener(MouseEvent.CLICK, editResClick); function editResClick(event:MouseEvent):void { navigateToURL(editRes, "_self"); } }
this should be in the as3 forum. but you need to return name/value pairs from your php file.
-
Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs. at Error$/throwError() at flash.net::URLVariables/decode() at flash.net::URLVariables() at flash.net::URLLoader/onComplete() _________________________________________________________________________________________ ____________ stop(); var DepartVars:URLVariables = new URLVariables(); var DepartURL:URLRequest = new URLRequest("scripts/www.mywebsite.com/depart.php"); DepartURL.method = URLRequestMethod.POST; DepartURL.data = DepartVars; var DepartLoader:URLLoader = new URLLoader; DepartLoader.dataFormat = URLLoaderDataFormat.VARIABLES; DepartLoader.addEventListener(Event.COMPLETE, completeDepart); depart_btn.addEventListener(MouseEvent.CLICK, DepartUser); // Function to run when the Depart button is pressed function DepartUser (event:MouseEvent):void{ // Ready the variables here for sending to PHP DepartVars.post_code = "Depart"; // Send the data to the php file DepartLoader.load(DepartURL); welcome_txt.text = "Processing request...Bon Voyage"; } // Close DepartUser function /////////////////////////////////////// // Function for when the PHP file talks back to flash function completedepart(event:Event):void{ if (event.target.data.replyMsg == "success") { var refreshPage:URLRequest = new URLRequest("javascript:NewWindow=window.location.reload(); NewWindow.focus(); void(0);"); navigateToURL(refreshPage, "_self"); } // Close completeDepart function ////////////////////////////// // Code for the View res Button var viewRes:URLRequest = new URLRequest("view_res.php"); viewRES_btn.addEventListener(MouseEvent.CLICK, viewResClick); function viewResClick(event:MouseEvent):void { navigateToURL(viewRes, "_self"); } ///////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////// // Code for the Edit Res profile Button var editRes:URLRequest = new URLRequest("edit_res.php"); editRES_btn.addEventListener(MouseEvent.CLICK, editResClick); function editResClick(event:MouseEvent):void { navigateToURL(editRes, "_self"); } }
I have a similar problem
whey I use .txt my code works, but when I change to .dat external file, it get error 1067
my code:
import flash.display.Sprite;
import flash.events.*;
import flash.net.URLLoader;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequest;
var loader: URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, loading);
loader.load(new URLRequest("rssnews.dat"));
function loading(e: Event): void {
news_1.text = trace(e.target.data.titulo);
news_2.text = trace(e.target.data.texto); -
How to send query string to OSB Business Service?
Hi
I need to call a Servlet which is accepting http get request.
My system design is
I have a web service interface that I need to expose to Front end application. I am using Proxy service for this.
Then I have a servlet at end system and using Business service to send request to servlet.
I need to pass username, password, jndi context and payload using url encoding.
What all steps do I need to follow for this? How to create query string , which variable I need to play with inbound or outbound?
I have gone through all the answers on this forum but could not understand much.
Thanks
VibhorHii
I am still unable to send http get request to end service.
In flow I have setted $outbound/transport/request-http/query-string too.
But I have to send request with url encoding.
How to encode query string and how can I check whether my request is going correctly or not, is there any variable in which complete url would be stored.
Thanks
Vibhor
Edited by: Vibhor Rastogi on Sep 15, 2010 9:49 AM -
Hi,
I need to pass htmlText to a server-side script via a
URLRequest, but I get this error because the html has single quotes
in it and is being sent via POST as a variable. How can I encode
the htmlText so it passes " \' " for each " ' "? I assume that will
solve the issue.
Error: Error #2101: The String passed to
URLVariables.decode() must be a URL-encoded query string containing
name/value pairs.
Thanks!I have the same problem (more or less, I have problems
sending & ) sending some html text to a php script and to solve
it I used RegExp:
var loader:URLLoader=new URLLoader;
var req:URLRequest=new URLRequest($php+'addmail.php');
var vars:URLVariables=new URLVariables;
var myp:RegExp = /&/g;
req.method='POST';
req.data=vars;
vars.oggetto=oggetto.text;
vars.argomento=argomento.text;
vars.data=data.text;
vars.allegato=allegato.text;
vars.corpohtml=htmltext.htmlText.replace(myp,'\&');
vars.corpotxt=htmltext.text.replace(myp,'\&');
loader.load(req);
loader.addEventListener(Event.COMPLETE,getRes);
function getRes():void {
var vrs:URLVariables=new URLVariables(loader.data);
if (vrs.result==1) {
Alert.show('Il mail e stato salvato','Confirm');
} else {
Alert.show('Il mail non puo essere salvato, riprovare piu
tardi!','Error');
} -
Error Message with Form Sending
Hi there,
My form is working fine and the PHP is fully functional,
however I get this error message once the form has been submitted.
Error: Error #2101: The String passed to
URLVariables.decode() must be a URL-encoded query string containing
name/value pairs.
at Error$/throwError()
at flash.net::URLVariables/decode()
at flash.net::URLVariables$iinit()
at
flash.net::URLLoader/flash.net:URLLoader::onComplete()
Does anyone know what this means?
Here is my function that sends the message
function sendMessage(event:MouseEvent):void
var contactVariables:URLVariables = new URLVariables();
contactVariables.custName = textName.text;
contactVariables.custEmail = textEmail.text;
contactVariables.custPhone = textPhone.text;
contactVariables.custSubject = textSubject.text;
contactVariables.custMessage = textMessage.text;
var postMessage:URLRequest = new
URLRequest("mailContact.php");
postMessage.data = contactVariables;
postMessage.method = URLRequestMethod.POST;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.load(postMessage);
gotoAndStop(2);
As mentioned before, my form does work fine. Anyone know what
the problem could be??
Thanks
CMOk ive figured out that Flash does not like the '&' sign
when data is sent back to it as a string. The thing that I dont get
is that my PHP script does NOT send the data back to flash. Why oh
why is this message being displayed?
Also ive discovered that on some machines it does not display
the error at all. I just don't get it. Anyone had this problem
before?
Thanks
CM -
Can anyone help why I am getting this error.
I am seeing these errors when I try to test my database. I
can't understand why. Does anyone have any ideas?
The exact file with different field names works on a
different table of the same database.
Thanks for the help.
Errors in ActionScript.
Error: Error #2101: The String passed to
URLVariables.decode() must be a URL-encoded query string containing
name/value pairs.
at Error$/throwError()
at flash.net::URLVariables/decode()
at flash.net::URLVariables()
at flash.net::URLLoader/onComplete()
AS3 CODE
// Changed the mouse event.
submit_btn.addEventListener(MouseEvent.CLICK, sendData);
function sendData(evt:Event) {
if (fname_txt.text!="" && lname_txt.text !=""
&& street_txt.text!="" && city_txt.text!=""
&& state_txt.text!="" && zip_txt.text!="") {
//for those using PHP
var myData:URLRequest = new URLRequest("
http://**********************");
myData.method = URLRequestMethod.POST;
var variables:URLVariables = new URLVariables();
variables.firstName = fname_txt.text;
variables.lastName = lname_txt.text;
variables.streetAddr = street_txt.text;
variables.cityName = city_txt.text;
variables.stateName = state_txt.text;
variables.zipCode = zip_txt.text;
myData.data = variables;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, dataComplete);
loader.load(myData);
} else {
status_txt.text = "All fields are mandatory";
function dataComplete(event:Event):void {
status_txt.text = event.target.data.successMessage;
//status1_txt.text = event.target.data.secondMessage;
fname_txt.text = "";
lname_txt.text= "";
street_txt.text = "";
city_txt.text = "";
state_txt.text = "";
zip_txt.text = "";
PHP CODE:
<?php
//Capture data from $_POST array
$fname = $_POST['firstName'];
$lname = $_POST['lastName'];
$street = $_POST['streetAddr'];
$city = $_POST['cityName'];
$state = $_POST['stateName'];
$zip = $_POST['zipCode'};
//Connection to database
$connect = mysql_connect("localhost", "**********",
mysql_select_db ("mttolcom_testDB", $connect);
//Perform the query
$result = mysql_query("INSERT into address (firstName,
lastName, streetAddr, cityName, stateName, zipCode) values
('$fname','$lname','$street','$city','$state','$zip')");
if($result) echo "writing=Ok&";
else echo "writing=Error";
echo 'var1=yes&successMessage=Response from server. The
data has made the server!';
// echo 'var2=yes&secondMessage=Your data has been
received and processed!';
?>
Thanks for the help.
MikeDear Jain,
I used CA Type 10 CA Categories as Stock Split for corporate action as below.
Configuration
FWK0 posting
Error Msg -
ok i am at the last part of my project. it worked all well and reads all text fields from a text file as seen on :
http://www.myblueranch.com/index2.html
now i am trying to get the same thing working from MYSQL.
Notice that the text file i used for index2.html is called
www.myblueranch.com/trees1.txt
and it was a direct copy/paste from the php page that gave the results from the MYSQL query. (the php query page is:)
www.myblueranch.com/flash_names.php
The problem is i am getting an error in
www.myblueranch.com/index.html
which uses the php to get the text for the dynamic fields.
I get the following error:
TypeError: Error #2007: Parameter text must be non-null.
at flash.text::TextField/set text()
at final_fla::MainTimeline/onDataLoad()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
my flash movie has 113 buttons called button_1 --> button_113 and 113 dynamic text fields tcname_1-->tcname_113
my AC3 code is the following:
// button links: to all buttons to open in iframe 'tdes'
// link corrosponds to button number
// i have 113 buttons.
for(var i:int=1;i<=130;i++){
if(this["button_"+i]){
this["button_"+i].addEventListener(MouseEvent.CLICK,f);
function f(e:MouseEvent):void{
var n:String=e.currentTarget.name.split("_")[1];
navigateToURL(new URLRequest("ranch.php?id="+n),"tdes");
// end of button links
//Create the URLLOader instance
var myLoader:URLLoader = new URLLoader()
//the data will come as URL-encoded variables
myLoader.dataFormat = URLLoaderDataFormat.VARIABLES
//Load using an URLRequest, even beeing local
myLoader.load(new URLRequest("flash_names.php"))
//onLoad handler listener
myLoader.addEventListener(Event.COMPLETE, onDataLoad)
//Error handling
myLoader.addEventListener(IOErrorEvent.IO_ERROR, onIOError)
myLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError)
//Could be an error or just a message
myLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, onHTTPStatus)
//add a listener for the complete event
function onDataLoad(evt:Event){
trace(evt.target.data.cant);
for(var i:uint=1; i<evt.target.data.cant; i++){
this["tcname_"+i].text = evt.target.data["tcname_"+i]
this["tcname_"+i].autoSize="left"
this["tcname_"+i].multiline = true;
this["tcname_"+i].wordWrap = true;
this["tcname_"+i].width = 70;http://forums.adobe.com/post!input.jspa?container=2066&containerType=14
this["tcname_"+i].visible = false;
this["button_"+i].addEventListener(MouseEvent.ROLL_OVER, buttonover);
this["button_"+i].addEventListener(MouseEvent.ROLL_OUT, buttonout);
trace(i);
// ON ROLLOVER make text field visible and change color
function buttonover(e:Event){
var tf:TextField=TextField(this["tcname_"+e.currentTarget.name.split("_") [1]]);
trace (tf.name);
tf.visible = true;
tf.textColor=0xff0000;
// ON ROLLOVER make change color and make invisible
function buttonout(e:Event){
var tf:TextField=TextField(this["tcname_"+e.currentTarget.name.split("_") [1]]);
tf.textColor=0x000000;
tf.visible = false;
//error callbacks
function onIOError(evt:IOErrorEvent){
trace("IOError: "+evt.text)
function onHTTPStatus(evt:HTTPStatusEvent){
trace("HTTPStatus: "+evt.status)
function onSecurityError(evt:SecurityErrorEvent){
trace("SecurityError: "+evt.text)Kenneth this created another problem:
1- i changed the code of the php to make it look like:
&tcname_1=Cherokee SweetGum&tcname_2=cedar&tcname_3=cedar&cant=3
and now i get this error:
Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.
at Error$/throwError()
at flash.net::URLVariables/decode()
at flash.net::URLVariables()
at flash.net::URLLoader/onComplete()
Also when i do that even when i load from a textfile (i.e. not from MYSQL through php) i see no text at all!!
2- Where did you want me to put these trace lines? if i put them in the end of my ac3 script i get this compile error:
Scene 1, Layer 'Layer 1', Frame 1, Line 97
1120: Access of undefined property evt.
did i do something wrong? -
Cannot pass variables from PHP to actionscript 3.0
I am using CS3 and I write the following code as to pass variable to flash from PHP
Actionscript
var myLoader:URLLoader = new URLLoader();
myLoader.dataFormat = URLLoaderDataFormat.TEXT;
var myRequest:URLRequest=new URLRequest("http://localhost/moodle/value.php");
myLoader.load(myRequest);
myLoader.addEventListener(Event.COMPLETE,onCompleteHandler);
var myValue: String;
function onCompleteHandler(e:Event):void{
var myvariable: URLVariables = new URLVariables(e.target.data);
myValue = myvariable.values;
trace(myValue);
PHP file
<?php
echo ('values = 8');
?>
But I always get the error and cannot get the values by using trace();
Before i try to use "myLoader.dataFormat = URLLoaderDataFormat.VARIABLES;" I still get the same error.
Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs
at Error$/throwError()
at flash.net::URLVariables/decode()
at flash.net::URLVariables$iinit()
at flash.net::URLLoader/flash.net:URLLoader::onComplete()
Can anyone help me?The error is fixed.The new version is like that
Actionscript
var myLoader:URLLoader = new URLLoader();
myLoader.dataFormat = URLLoaderDataFormat.TEXT;
var myRequest:URLRequest=new URLRequest("http://localhost/moodle/value.php");
myLoader.load(myRequest);
myLoader.addEventListener(Event.COMPLETE,onCompleteHandler);
var myValue: String;
function onCompleteHandler(e:Event):void{
var myvariable: URLVariables = new URLVariables(e.target.data);
myValue = myvariable.values;
trace(myValue);
php file
<?php
echo "values=8";
?>
The output finally is "null" in flash file. Why does it happen? It should give me 8 when I input trace(myValue); -
Displaying image from Webserver on to a Swing application
Hi guys,
We're developing an application that is typically swing <-> servlet <-> database.We want to retrieve an image present on the server system through a servlet( which actually gets the path of the image stored in the database and returns that image file on the HDD of server system as a byte[ ]).
My problem is im reading the image from the byte[ ] on the swing client and creating a new .gif file on the client system but couldnt create its dimensions.hence not able to display it on my app.Plz help.Thx for ur consideration.
my code looks as -
//this is Swing client
try
String query="select imgpath from emp_img where eid=1";
URL u=new URL("http://127.0.0.1:8080/servlets-examples/servlet/ImgServ?query="+URLEncoder.encode (query));
URLConnection uc=u.openConnection();
ObjectInputStream ois=new ObjectInputStream(uc.getInputStream());
byte b[]=(byte[])ois.readObject();
System.out.println("b size= "+b.length);
FileOutputStream fos=new FileOutputStream("emp.gif");
fos.write(b);
Graphics g=EmpImg.getGraphics(); //EmpImg is JButton
EmpImg.setIcon(new ImageIcon("emp.gif","pic"));
EmpImg.updateUI();
catch()......
bye
neilHi guys,
We're developing an application that is typically
swing <-> servlet <-> database.We want to retrieve an
image present on the server system through a servlet(
which actually gets the path of the image stored in
the database and returns that image file on the HDD of
server system as a byte[ ]).
My problem is im reading the image from the byte[ ] on
the swing client and creating a new .gif file on the
client system but couldnt create its dimensions.hence
not able to display it on my app.Plz help.Thx for ur
consideration.
my code looks as -
//this is Swing client
try
String query="select imgpath from emp_img where
eid=1";
URL u=new
URL("http://127.0.0.1:8080/servlets-examples/servlet/Im
Serv?query="+URLEncoder.encode (query));
URLConnection uc=u.openConnection();
ObjectInputStream ois=new
ObjectInputStream(uc.getInputStream());
byte b[]=(byte[])ois.readObject();
System.out.println("b size= "+b.length);
FileOutputStream fos=new FileOutputStream("emp.gif");
fos.write(b);
Graphics g=EmpImg.getGraphics(); //EmpImg is JButton
EmpImg.setIcon(new ImageIcon("emp.gif","pic"));
EmpImg.updateUI();
catch()......
bye
neilAre sure that you've closed fos?
fos.close();Probably file is incomplete?
Paul -
Datagrid populated from mysql dbase using php
There are three methods: loadvars, xml and flash remoting.
I have a great tutorial from Lee Brimlow but he only passes one column into a listbox.
I want various columns passed into a datagrid.
I'm not too sure how to amend the php code
<?PHP
$link = mysql_connect("Localhost","user","password");
mysql_select_db("cambridgekidsdb");
$query = 'SELECT * FROM trivia_user';
$results = mysql_query($query);
echo "<?xml version=\"1.0\"?>\n";
echo "<triviauser>\n";
while($line = mysql_fetch_assoc($results)) {
echo "<item>" . $line["user_name"] . "</item>\n";
echo "</triviauser>\n";
mysql_close($link);
?>
How do I "echo" out the other columns.
The flash AS3 code is:
var theXML:XML = new XML();
theXML.ignoreWhite = true;
theXML.onLoad = function() {
var nodes = this.firstChild.childNodes;
for(i=0;i<nodes.length;i++) {
theGrid.addItem(nodes[i].firstChild.nodeValue,i);
theXML.load("http://www.cambridgekids.es/trivia_user.php");
I'm almost there and this will be fundamental to my website as I can create important stats on hundreds of children.
Thank you in advance.Hi.
I have a lot better understanding of everything from so many tutorials and googling so that's a bonus.
I now have AS3 and using URLVariables
The php code is perfect because on linking to the php file it echos (prints) the correct name = value sintax/format
However, flash emits an error message:
Error: Error #2101:
The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs
at Error$/throwError()
at flash.net::URLVariables/decode()
at flash.net::URLVariables()
at flash.net::URLLoader/onComplete()
<?php
//$username = $_POST['username']; //the second user name was a variable POSTED from flash and assigned here to $username
$username = 'DAVIDSAUGAR';
mysql_connect("localhost","user","password") or die (mysql_error());
mysql_select_db("cambridgekidsdb") or die ("no database");
$sql = mysql_query("SELECT user_name, user_id FROM trivia_user WHERE user_name='$username' LIMIT 1");
while($row = mysql_fetch_array($sql)) {
$theName = $row['user_name'];
echo "usernameToFlash=$theName";
mysql_close();
?>
FLASHCODE
stop();
var variables:URLVariables = new URLVariables();
var varSend:URLRequest = new URLRequest("www.cambridgekids.es/trivia_user.php");
varSend.method = URLRequestMethod.POST;
varSend.data = variables;
var varLoader:URLLoader = new URLLoader;
varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
varLoader.addEventListener(Event.COMPLETE, completeHandler);
variables.username = "DAVIDSAUGAR";
varLoader.load(varSend);
function completeHandler(event:Event):void{
var user = event.target.data.usernameToFlash;
graphTitle_txt.text = user;
You are probably thinking WHY am I passing in a username to get the same username out - well I'm only testing at the moment. -
Special characters in String variable sent from php.
Hello. Assuming that I send some String variable from php into flash:
AS3:
var MyImportedString:String;
var variables_page_text:URLVariables = new URLVariables();
var varSend_page_text:URLRequest = new URLRequest("MyPHP.php");
varSend_page_text.method = URLRequestMethod.POST;
varSend_page_text.data = variables_page_text;
var varLoader_page_text:URLLoader = new URLLoader;
varLoader_page_text.dataFormat = URLLoaderDataFormat.VARIABLES;
varLoader_page_text.addEventListener(Event.COMPLETE, var_comp_page_text);
varLoader_page_text.load(varSend_page_text);
function var_comp_page_text(event:Event):void {
MyImportedString = event.target.data.MyVariable;
php:
<?php
header('Content-Type: text/html; charset=utf-8');
$MyString = "some tekst &";
print "MyVariable=" . $MyString;
?>
I've noticed that the special character '&' residing inside String, throws an error: #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.
My first thought was, it has something to do with html entities, but other entities (like <> or ") don't throw any error. Besides, the use of php functions like htmlentities(); or html_entity_decode(); doesn't make any difference in this case:
print "MyVariable=" . htmlentities($MyString);
or
print "MyVariable=" . html_entity_decode($MyString);
I've also noticed that characters like '%', '^', '+' don't show up at all;
What does it mean? Any ideas?
Reagards.Thank You 'moccamaximum'.
Ok. So here is the solution (php function posted by 'moccamaximum' does the trick):
AS3:
var MyImportedString:String;
var variables_page_text:URLVariables = new URLVariables();
var varSend_page_text:URLRequest = new URLRequest("MyPHP.php");
varSend_page_text.method = URLRequestMethod.POST;
varSend_page_text.data = variables_page_text;
var varLoader_page_text:URLLoader = new URLLoader;
varLoader_page_text.dataFormat = URLLoaderDataFormat.VARIABLES;
varLoader_page_text.addEventListener(Event.COMPLETE, var_comp_page_text);
varLoader_page_text.load(varSend_page_text);
function var_comp_page_text(event:Event):void {
MyImportedString = event.target.data.MyVariable;
trace(MyImportedString); // Output: some text &%^+
php:
<?php
header('Content-Type: text/html; charset=utf-8');
$MyString = "some text &%^+";
print "MyVariable=" . flash_encode($MyString);
function flash_encode($string){
$string = rawurlencode(utf8_encode($string));
$string = str_replace("%C2%96", "-", $string);
$string = str_replace("%C2%91", "%27", $string);
$string = str_replace("%C2%92", "%27", $string);
$string = str_replace("%C2%82", "%27", $string);
$string = str_replace("%C2%93", "%22", $string);
$string = str_replace("%C2%94", "%22", $string);
$string = str_replace("%C2%84", "%22", $string);
$string = str_replace("%C2%8B", "%C2%AB", $string);
$string = str_replace("%C2%9B", "%C2%BB", $string);
return $string;
?> -
Applet/Servlet communication - StreamCorruptedException
Hi, I'm having a problem when I try to connect to a servlet. I am using applet/servlet communication. The problem only occurs when I have lauched a crystal report via http in a new window.
After the report is launched if I try to hit my servlet I get the following error:
java.io.CorruptedStreamException: invalid stream header
Not all crystal reports I launch cause this behavior but I can see nothing in the url I use to launch the report that is out of place or different than other reports.
APPLET-SERVLET CONNECTION
try {
StringBuffer path = new StringBuffer();
path.append(ip);
path.append("servlet/DatabaseServlet?");
path.append("option=getRecords&query=").append(URLEncoder.encode(query,"UTF-8"));
URL url = new URL(path.toString());
URLConnection servletConnection = url.openConnection();
servletConnection.setUseCaches(false);
servletConnection.setDoInput(true);
servletConnection.setDoOutput(true);
servletConnection.setRequestProperty("Content-Type", "application/x-java-serialized-object");
ObjectInputStream inputFromServlet = new ObjectInputStream(servletConnection.getInputStream());
rc = (RecordCollection) inputFromServlet.readObject();
inputFromServlet.close();
} catch (Exception e) {
e.printStackTrace();
SERVLET CODE
Forwards to doPost
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("session id: " + request.getSession().getId());
this.doPost(request, response);
LAUNCHING REPORT FROM APPLET
try {
String launchURL = host + directory + report + "?promptOnRefresh=0"+ "&" +
authentication + "&" + key + "&" + startPeriods + "&" + reportYears + "&" + reportTitle + "&" endPeriods "&" + locations + "&" + reportPeriod + "&" + fiscalWeek + "&" + fiscalYear + "&" +time;
context.showDocument(new URL(launchURL), "_blank");
} catch (Exception ex) {
ex.printStackTrace();
SAMPLE URL THAT CAUSES PROBLEM
http://localhost:113/Reports/OpenToBuy_3.class?promptOnRefresh=0&user0=rpuser&password0=er34sw1&[email protected]=rpuser&[email protected]=er34sw1&user0@sub2=rpuser&[email protected]=er34sw1&promptex-key="L","L1","ALL"&promptex-start="1"&promptex-years="2004","2004"&promptex-title="Report Title"&promptex-end="1"&promptex-locs="01","03","04","05"&promptex-period="Feb 2004 [04-01]"&promptex-cw="1"&promptex-cy="2004"&promptex-time=-2-52728"
Everything works fine until I launch this report then I can no longer get data from my servlet. I thought the URL lenght for the report might be the problem but I lauch a report with a URL longer than the problem one and there I don't get the errors after. When I try to connect to the servlet the println statement in the doGet method of my servlet doesn't get printed so it's not even making it inside that method in the servlet.
Anyone have any idea what could be causing this? Anyone have any ideas what would be causing this? I'm really stumped.I've seen this problem before. Because your accessing a complete URL (ie http://<host>:<port>/xxx), you are actually creating a new session. Whenever the applet opens a connection to a servlet it is running on it's own session not the same as the JSP. This is rather obvious since the Page and Applet are separate entities.
Try sending authentication with the url. I think the syntax is:
username:password@http://localhost/xxx
However I'm not sure how well this might work for Tomcat. As for Java it may try and throw a MalformedURLException I would have to test it first - it's been a long time since I used this technique!
Wish I could be more help,
Anthony -
Processing a PHP variable in AS3
I have looked in every book that I have on AS3 and cannot
come up with a solution to this, I hope that someone can help me.
I am receiveing a data string from a PHP --- mySQL connection
on my web server. The string is arriving in flash as I can trace it
and see the variables. If I do a trace on event.target.data I see
the following.
&numResult1=4&numResult2=14&numResult3=37&numResult4=70&numResult5=5&numResult6=3&doneLoad ing=true
This is exactly what I should be seeing based on my PHP code.
I am trying to assign the numResult numbers to a dynamic text
box, for instance numResult1 = 4, I would like to assign that 4 to
a dynamic text field on the Flash Stage. I have not figured out a
way to get the variable out of the string.
I keep getting undefined or a variety or other errors with
the different methods I try.
I have tried numerous ways using the URLVariables class but I
have had no luck. Use to be very simple in AS2, I could assign the
variable right to the dynamic text field in the properties panel,
not anymore.
Does anyone know how I can do this. People are doing it all
the time, it can't be that hard, is it?????
Just a good example as to how to break the variables out
would be really helpful. I have tried the FlashGods site and could
not figure there examples out, in fact the two I tried did not work
at all.
I would appreciate any help.... Thank you.
MikeI have been trying to work this through for over a week, here
is the ActionScript Code;
AS
function getData(event:Event):void {
var myURLLoader:URLLoader = new URLLoader();
var myURLRequest:URLRequest = new URLRequest("polls2.php");
// Actually goes to a web site.
myURLLoader.dataFormat=URLLoaderDataFormat.TEXT;
myURLLoader.load(myURLRequest);
myURLLoader.addEventListener(Event.COMPLETE,
completeHandler);
function completeHandler(event:Event):void {
trace(myURLLoader.data);
var myURLVariables:URLVariables = new
URLVariables(myURLLoader.data);
gotoAndStop(2);
Here is what I get with the Trace Statement:
&numResult1=6&numResult2=6&numResult3=5&numResult4=9&numResult5=7&numResult6=1&doneLoading =true
Here is what I get when I try to set the URL variables.
Error: Error #2101: The String passed to
URLVariables.decode() must be a URL-encoded query string containing
name/value pairs.
at Error$/throwError()
at flash.net::URLVariables/decode()
at flash.net::URLVariables()
at MethodInfo-2()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
Now it sure looks to me that the string being passed is
name/value pairs.
I have tried every way that I can think of to capture this
data. I must be missing something simple.
Any ideas would be greatly appreciated.
Thanks for your help.
Mike -
Error #2101 when loading variables?
Hi!
I got a problem with loading varables form a php file, here's tha as code:
var loader:URLLoader = new URLLoader();
// specify format as being variables
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, varsLoaded);
// vars.txt contents: foo=bar&foo2=bar2
loader.load(new URLRequest("http://www.gbgknappen.se/designitonline/dekaldesigner/load_pris.php"));
function varsLoaded (event:Event):void {
trace(loader.data is URLVariables); // true
trace(loader.data.foo); // bar
trace(loader.data.foo2); // bar2
pris_ruta.text=loader.data.foo2+loader.data.foo;
And here's the simpel php code:
<?php
echo "foo=bar&foo2=bar2";
?>
Got error message: Error #2101 The string passed to URLVariables.decode () must be a URL-encoded query string containing name / value pairs.
What can be wrong in the code?try to write your php code with notepad.
There could be invisible characters when using Dreamweaver or similar softwares.
Maybe you are looking for
-
Problem with popup in a page fragment
JDev 11.1.2.1 I'm using the code described here to launch popup from a backing bean. http://www.oracle.com/technetwork/developer-tools/adf/learnmore/oct2010-otn-harvest-183714.pdf How-to launch a popup programmatically from Java Starting Oracle JDeve
-
BPC 7.5 : Error in deleting member from dimension
Hi All In BPC 7.5, I have created earlier one member "F_P/L"in Flow Dimension and tested some data. Now I want to delete the member "F_P/L" from the Flow Dimension and while processing it, I am getting following error : " Dimension
-
Oracle 10g : XML* packages have become synonyms of DBMS_XML* paclages
Hello, I noticed that old 9i XML* packages are now synonyms for DBMS_XML* packages. Those package in Oracle 9i were different from the DBMS_ packages. Now my application is not working anymore because we are now Is there a kit to install on 10g to ge
-
The disk you inserted was not readable by this computer - MAC
I just purchased a Droid Incredible and would like to transfer photos. After reading other Droid forums, I simply plugged my device into my MacBook Pro (OSX) and got this message: "The disk you inserted was not readable by this computer." Any suggest
-
When I delete videos from my media card, the playlist on the device still lists the deleted videos. How can I update the playlist to only reflect currently loaded files? Thanks. Solved! Go to Solution.