views:

106

answers:

3

Hi,

I'm a flex noob and I have a few doubts regarding the Httpservice class,

  1. Can I use it to fetch data from a file that resides in my own server or can I use it to download any url like external sites like google or stackoverflow (even ones without an api)?

  2. Does httpservice behave differently based on whether it is an desktop app or webapp?

In short, does it behave like a httpclient(like libcurl and mechanize) or does it have restrictions(like xmlhttprequest)?

A: 

It's more like XmlHttpRequest. In fact it's even more limited.

Flex's HTTP support is terrible. At my firm, we classify it as a "crippled" client.

Avi Flax
Can you provide more details? Flash Player's HTTP restrictions are primarily due to browser restrictions (like same-domain) or NSPAPI limitations (like no PUT, DELETE, etc).
James Ward
- It can't send the request header `Authorization`, so it can't use HTTP Basic Authentication - If the Status Code of a response is anything other than 200 — even 201, 202, or 204 — the response is treated as an error, the request is considered to have failed, and it's hard or impossible to access the response headers or response body - In general it's hard or impossible to access response headers…and that's just off the top of my head; there's more.
Avi Flax
A: 
  1. Yes you can use HttpService to fetch data from your own server.

  2. Its like XMLHttpRequest, you send requests asynchronously. For syncronous behaviour or to replicate HttpClient i think you can use the NetConnection class of ActionScript.

Rajat
There are no synchronous IO APIs in Flash.
James Ward
Thanks for correcting me on this one.
Rajat
+3  A: 

Flex's HTTPService library is a convenience API on top of the underlying HTTP networking APIs in Flash Player. So you can only use it for things that Flash Player supports.

  1. Browsers have a same-domain / same-origin policy for network requests. So an application loaded from foo.com can only get data from foo.com. However Flash Player provides a mechanism for getting around this using crossdomain policy files. They are however dangerous and a better solution is to use a proxy like BlazeDS or Apache so that you don't violate the same-origin policy.

  2. There are some subtle differences between the HTTP networking APIs in Adobe AIR and Flash Player. One of the primary differences is that Adobe AIR applications do not have a same-origin policy.

James Ward
thanks for the answer, exactly what i needed to know
foobar