gabriel / as3httpclient Goto Github PK
View Code? Open in Web Editor NEWHTTP Client for AS3
License: MIT License
HTTP Client for AS3
License: MIT License
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);
}
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 :
Am I missing anything.Plz help.
Thanks,
Hishankjain
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]
Hi,
We're getting "GOT ALERT! type=0" when we make a PUT request to Amazon S3 using HTTPS. What might be going on?
When using https to get data, it prompts "TLSEngine shutdown triggered by Error: Cannot verify certificate"
var client:HttpClient = new HttpClient();
var uri:URI = new URI("https://www.baidu.com/");
uri.scheme = "https";
uri.port = "443";
var variables:Array = [ { name: "fname" } ];
client.postFormData(uri,variables);
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 );
}
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.
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?
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.
Has this project been updated to use it/
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?)
Dear gabriel,
I plan to use your lib to communicate with Comet server, is this possible?
Do you have any sample?
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.