views:

158

answers:

1

I am sending two parameters to a php script. The php script works fine if I use the browser to run the script and pass parameters to it like http://www.somewebsite.com/runScript.php?id=aaa&name=bbb. But when I use the Flex httpservice, the parameters are not passed to the script.

 <s:HTTPService url="http://www.somewebsite.com/runScript.php"
    id="verifyUserService"
    result="verifyUserResult(event)"
    fault="verifyUserFault(event)"
    method="GET"
    contentType="application/xml"
    useProxy="false">
   <mx:request xmlns="">
     <id>
        {userId}
     </id>
     <name>
        {username}
     </name>
   </mx:request>

 </s:HTTPService>

I checked the Network Monitor and the parameters are being sent:

POST /runScript.php HTTP/1.1 Referer: app:/AIMTSJC.swf Accept: text/xml, application/xml, application/xhtml+xml, text/html;q=0.9, text/plain;q=0.8, text/css, image/png, image/jpeg, image/gif;q=0.8, application/x-shockwave-flash, video/mp4;q=0.9, flv-application/octet-stream;q=0.8, video/x-flv;q=0.7, audio/mp4, application/futuresplash, /;q=0.5 x-flash-version: 10,1,53,64 Content-Type: application/xml Content-Length: 33 User-Agent: Mozilla/5.0 (Windows; U; en-US) AppleWebKit/531.9 (KHTML, like Gecko) AdobeAIR/2.0.2 Host: www.somewebsite.com

aaabbb

Returned response:

HTTP/1.1 200 OK Date: Thu, 02 Sep 2010 02:58:54 GMT Server: Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.7d PHP/5.2.8 X-Powered-By: PHP/5.2.10 Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Set-Cookie: PHPSESSID=pa81b900ddff7c0b61c44c3380g3590fb; path=/ Transfer-Encoding: chunked Content-Type: text/html

id: name:

My php script:

 // Get the id and name.
 $uid= $_GET["id"];
 $uname= $_GET["name"];
 echo "uid: ".$uid;
 echo "uname: ".$uname;

I form a query and send to the database. The query is successful when I type the http://... as mentioned above on the browser URL. Both the uid and uname got the correct parameters. But when I run the httpservice, both uid and uname has no parameters, and the query fails.

Any help is appreciated!

Thanks in advance, aobs

A: 

Look again at your network monitor output. It's actually going via POST, so your $_GET will be empty:

POST /runScript.php HTTP/1.1 Referer: app:/AIMT etc....
^^^^---post, not get
Marc B
Actually I tried changing the $_GET to $_POST before and tried it again just now, the $uid and $uname is still empty.
aobs
aobs
Can't tell from your example, but `aaabbb` would not be a valid xml document, if that's what you're trying to send to the web service. Perhaps the tags got stripped/hidden when you pasted it here, but either way, it's not xml, amf, or json
Marc B
The tags did get stripped. The full line in Raw View is <id>aaa</id><name>bbb</name>. Really don't know what went wrong. Does not seem to be a problem with the xml.
aobs
OK! I found the answer. You got me reexamine the HTTPService code. I removed the contentType="application/xml" line and it is working now.
aobs