GithubHelp home page GithubHelp logo

as3httpclient's Introduction

An HTTP/HTTPS client library for Actionscript 3.

This is really old and unsupported!

Building

To build the swc:

compc -load-config=build-swc.xml

To build and run tests under airake:

rake
rake test
rake adl

For info on airake, which is used to build and test see: http://airake.rubyforge.org/ and http://github.com/gabriel/airake/tree/master

Info

If anybody from Adobe is reading this: Please add outputProgress event to Socket. (This is the same behavior as outputProgress event in FileStream?) Otherwise it is impossible to determine the ouput progress on socket writes.. see http://rel.me/2008/1/17/socket-output-progress-in-air for more info.

Everyone else: Vote for the fix!

In order to use flash.net.Socket in a Flash sandbox environment, you need to have a flash socket policy server. (AIR does not have this restriction.) Look at http://www.adobe.com/devnet/flashplayer/articles/socket_policy_files.html. To debug in the environment, I would use a standalone flash debug player with logging configured and you will see it attempt to connect to flash socket policy server at port 843. Because of this restriction, this library might be more suited for AIR apps. HTTPS doesn't always work. There are some minor bugs with the as3crypto library, so for example https at yahoo and yahoo owned domains (like delicious) don't currently work.

Goals

The goals for this project are:

  • Learn the HTTP protocol by trying to implement a client.
  • Use AS3Crypto TLSSocket support for implementing HTTPS.
  • Use it as a replacement for Flash's URLRequest/URLStream API.
  • Support the Flash and AIR runtimes.

Working:

  • GET, HEAD, PUT, POST, DELETE, PATCH
  • multipart/form-data (PUT, PATCH and POST)
  • HTTPS support using AS3Crypto TLS
  • Post with application/x-www-form-urlencoded
  • Reading chunked (Transfer-Encoding)

Next to implement:

  • The other http verbs
  • Connection keep-alive
  • gzip compression
  • ...

For examples see, EXAMPLES

as3httpclient's People

Contributors

espenhogbakk avatar gabriel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

as3httpclient's Issues

https timeout error

Hi,

I am trying to to send https post request(port 81) to my server from main swf file(loaded from port 99).

Code in my main.swf:
uri = new URI("https://x.x.x.x/myservice.aspx");
uri.scheme = "https"
uri.port = "81";
client.postFormData(uri,variables);

It traces:
Warning: Found secure='true' in policy file from xmlsocket://x.x.x.x:843, but host x.x.x.x does not appear to refer to the local machine. This may be insecure. See http://www.adobe.com/go/strict_policy_files for details.

OK: Policy file accepted: xmlsocket://x.x.x.x:843

OK: Request for resource at xmlsocket://x.x.x.x:81 by requestor from https://x.x.x.x:99/webdev/allfiles/main.swf is permitted due to policy file at xmlsocket://x.x.x.x:843

Request URI: https://x.x.x.x:81/webdev/myservice.aspx (POST)

But I dont get any response from the server & I receive following error after some time:-

[ErrorEvent type="httpTimeoutError" bubbles=false cancelable=false eventPhase=2 text="Timeout"]

Error: Error #2002: Operation attempted on invalid socket.
at flash.net::Socket/flush()
at com.hurlant.crypto.tls::TLSSocket/close()
at com.org.httpclient::HttpSocket/close()
at com.org.httpclient::HttpSocket/onTimeout()
at com.org.httpclient::HttpTimer/onTimer()
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()

Things I have done :

  1. Returned a policy file at socket 843 on server.
  2. Crossdomain file at root of my server.
  3. Bind server port 81,443 & 99 to https request.
  4. created rule to allow all TCP/UDP connection over all ports.

Am I missing anything.Plz help.

Thanks,
Hishankjain

could I merge in socket OutputProgressEvent support?

Thank you for making this wonderfully cleanly coded library. It lets us all have the full control we need to talk to servers in the way we want.

I have implemented support for OutputProgressEvent events on socket writes. This allowed me to finally upload large photos efficiently.

I would like to submit my modest changes to the main branch. Are you interested? If so, what is the best way of doing that?

Http push

Dear gabriel,

I plan to use your lib to communicate with Comet server, is this possible?
Do you have any sample?

Thanks

HTTP Header parser

using /r/n to parse HTTP header can be faulty. Would suggest using finite state machine strategy.

Please find the following snippet, hope it helps.

Cheers,
Ping

           /**
     * parse HTTP header
     */ 
    public function parseHeader():void
    {
        _data.position = 0;
        var response:String = _data.readUTFBytes(_data.length);
        _cursor = 0;
        while(_cursor < response.length)
        {
            var ch:String = response.charAt(_cursor);
            switch(_state)
            {
                case RESPONSE_START:
                    if (ch == "H")
                    {
                        _state = RESPONSE_VERSION;
                        _version += ch;
                    }
                    break;
                case RESPONSE_VERSION:
                    if (ch == " ")
                    {
                        _state = RESPONSE_WAIT_STATUS;
                        //_logger.debug("version: " + _version);
                    }
                    else
                    {
                        _version += ch;
                    }
                    break;
                case RESPONSE_WAIT_STATUS:
                    if (ch != " ")
                    {
                        _state = RESPONSE_STATUS_CODE;
                        _statusCode += ch;
                    }
                    break;
                case RESPONSE_STATUS_CODE:
                    if (ch == " ")
                    {
                        _state = RESPONSE_WAIT_STATUS_INFO;
                        //_logger.debug("status code: " + _statusCode);
                    }
                    else
                    {
                        _statusCode += ch;
                    }
                    break;
                case RESPONSE_WAIT_STATUS_INFO:
                    if (ch != " ")
                    {
                        _state = RESPONSE_STATUS_INFO;
                        _statusInfo += ch;
                    }
                    break;
                case RESPONSE_STATUS_INFO:
                    if (ch == "\r")
                    {
                        _state = RESPONSE_CR;
                        //_logger.debug("status info: " + _statusInfo);
                    }
                    else
                    {
                        _statusInfo += ch;
                    }
                    break;
                case RESPONSE_CR:
                    if (ch == "\n")
                    {
                        _state = RESPONSE_LF;
                    }
                    break;
                case RESPONSE_LF:
                    if (ch == "\r")
                    {
                        _state = RESPONSE_HDR_ALMOST_DONE;
                    }
                    else
                    {
                        _state = RESPONSE_KEY;
                        _keyTemp += ch;
                    }
                    break;
                case RESPONSE_KEY:
                    if (ch == ":")
                    {
                        _state = RESPONSE_KEY_SPACE;
                        _key = _keyTemp;
                        _keyTemp = "";
                        //_logger.debug("KEY: " + _key);
                    }
                    else
                    {
                        _keyTemp += ch;
                    }
                    break;
                case RESPONSE_KEY_SPACE:
                    if (ch != " ")
                    {
                        _state = RESPONSE_VALUE;
                        _valueTemp += ch;
                    }
                    break;
                case RESPONSE_VALUE:
                    if (ch != "\r")
                    {
                        _valueTemp += ch;
                    }
                    else
                    {
                        _state = RESPONSE_CR;
                        _value = _valueTemp;
                        _valueTemp = "";
                        _httpHeader.add(_key, _value);
                        //_logger.debug("VALUE: " + _value);
                    }
                    break;
                case RESPONSE_HDR_ALMOST_DONE:
                    if (ch == "\n")
                    {
                        _state = RESPONES_HDR_DONE;
                    }
                    break;
            } // end of switch
            _cursor ++;
            if (_state == RESPONES_HDR_DONE) break;
        } // end of while

        _httpResponse = new HttpResponse(_version, _statusCode, _statusInfo, _httpHeader);
    }

TLSSocket error (not defined )

Hi Gabriel, I'm getting this error below, do you have a clue why this is happening?
Does it have something to do with the policy server?
Thanks in advance!

ReferenceError: Error #1065: Variable com.hurlant.crypto.tls::TLSSocket is not defined.
at org.httpclient::HttpSocket/onResponseComplete()[/Users/gabe/Projects/as3httpclient/src/org/httpclient/HttpSocket.as:272]
at org.httpclient.io::HttpResponseBuffer/writeBytes()[/Users/gabe/Projects/as3httpclient/src/org/httpclient/io/HttpResponseBuffer.as:121]
at org.httpclient::HttpSocket/onSocketData()[/Users/gabe/Projects/as3httpclient/src/org/httpclient/HttpSocket.as:259]

GOT ALERT! type=0

Hi,
We're getting "GOT ALERT! type=0" when we make a PUT request to Amazon S3 using HTTPS. What might be going on?

"Error: No data available" raised in HttpBuffer.as, resolved

Thanks for the library, I've found it to be quite useful! It does have a bug that I encountered during development that I eventually hunted down and resolved.

Every once in a while, the error "No data available" will be thrown from HttpBuffer.readChunks() when readLine() returns null. This will occur when the chunk size (e.g. "3ef\r\n") is split between two TCP packets, something that is infrequent but still allowed. The fix is quite simple, just change the line:
throw new Error("No data available");
To:
return false;
That's currently line 115 of src/org/httpclient/io/HttpBuffer.as.

Can't re-dispatch events

Currently its impossible to re-dispatch events. For example...

private function statusHandler( event:HttpStatusEvent ):void
{
    dispatchEvent( event );
}

It will throw this error:

TypeError: Error #1034: Type Coercion failed: cannot convert flash.events::Event@16be0a1 to org.httpclient.events.HttpStatusEvent.

To fix, override the clone() method in your event classes. For example:

override public function clone():Event 
{
    return new HttpStatusEvent( response, type, bubbles, cancelable );
}

POST fails with ByteArray body with position != 0

When making a POST request, if the request.body is a ByteArray and the array is not at position 0 the request fails.

This looks to be because the Content-Length header is set based on the .length of the body, however during transport it expects there to be .length bytes of data after the current position. It would at least be worth a warning in the documentation for HttpRequest (or possibly changing the code to generate Content-Length using .bytesAvailable instead of .length?)

Dependency on com.hurland

There is a dependency on com.hurland, might want to mention this in the docs.

https://github.com/gabriel/as3httpclient/blob/master/src/org/httpclient/HttpSocket.as#L8

I downloaded the com.hurland files, but the dependency fails for me:

Error: Error #2030: End of file was encountered.
    at flash.utils::ByteArray/readShort()
    at com.hurlant.crypto.tls::TLSEngine/parseHandshakeHello()[/tmp/test/com/hurlant/crypto/tls/TLSEngine.as:434]
    at com.hurlant.crypto.tls::TLSEngine/parseHandshake()[/tmp/test/com/hurlant/crypto/tls/TLSEngine.as:312]
    at com.hurlant.crypto.tls::TLSEngine/parseOneRecord()[/tmp/test/com/hurlant/crypto/tls/TLSEngine.as:228]
    at com.hurlant.crypto.tls::TLSEngine/parseRecord()[/tmp/test/com/hurlant/crypto/tls/TLSEngine.as:206]
    at com.hurlant.crypto.tls::TLSEngine/dataAvailable()[/tmp/test/com/hurlant/crypto/tls/TLSEngine.as:139]

Any idea what the problem is? In case the script is a wrong version, perhaps you can include the specific version that is working with this script in the repository.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.