What is the difference between URLLoader and URLRequest in Actionscript? - actionscript

What is the difference between URLLoader and URLRequest in Actionscript?

URLRequest prepares a url to be used by any service in Flash that needs to communicate with a server, capturing all of the information in a single HTTP request.
The URLLoader, on the other hand, is used to download data from a URL as text, binary data, or URL-encoded variables.

Related

How I can get the complete URL by using NEPacketTunnelProvider?

By using NEPacketTunnelProvider I am able to get the destination host address, but I can not get the complete URL, is there any possibility that I can get the complete URL?
If you are referring to capturing a HTTP request path, you will need to sniff each Data packet by parsing each header until you get to the HTTP layer and determine the request path. It would likely take a bit of work to develop the packet parsing structure in Swift, and wouldn't work with HTTPS.

How to change the URL when using NSURLSession downloadTaskWithResumeData:?

I use NSURLSession downloadTaskWithURL: to download a file, and use NSURLSessionDownloadTask cancelByProducingResumeData: to produce an NSData and save it to a local temp file.
Then I want to resume the download task by using NSURLSession downloadTaskWithResumeData:.
There's a problem, the URL I used to download the file is a temp url, I need to request a new URL to download the same file.
After using downloadTaskWithResumeData: , it helps me to create a NSURLSessionDownloadTask with the same URL as before.
How can I replace the URL with the new URL that I newly request?
Or how can I change the HTTP Request of this NSURLSessionDownloadTask?
How do you deal with the situation that resume a NSURLSessionDownloadTask with a different URL?
I'm thinking about to get the .tmp file that NSURLSession downloaded, and set the Range in HTTP Header, then write to this file with the new temp URL.
I don't believe that we can resume download if the path of the resource has been modified.
According to Apple Developer Class Reference:
A download can be resumed only if the following conditions are met:
The resource has not changed since you first requested it
The task is an HTTP or HTTPS GET request
The server provides either the ETag or Last-Modified header (or both) in its response
The server supports byte-range requests
The temporary file hasn’t been deleted by the system in response to disk space pressure
Also as we see, there is no way we can modify URL programmatically while resuming a download. We just have an option to provided the partially downloaded data.

How do I retrieve a complete HTTP response from a web server including response body using an Indy TIdTCPClient instance?

I have a Delphi 6 application that uses an Indy TIdTCPClient instance to communicate with a web server. The reason I am not using an HTTP client directly is because the the server is an image streaming server that uses the same socket connection for receiving the command to start streaming as it does to start "pushing" images back to you. In other words, after you send it a typical HTTP POST request, it replies with an HTTP response, and immediately after that it starts sending out a stream of JPEG images.
I already know how to craft a proper POST request and send it using the TIdTCPClient WriteBuffer() method and then use the ReadBuffer() method to receive reply data. What I'd like to do instead is to send a POST request and then ask Indy to wait for a typical HTTP response including retrieving all the bytes in the response body if there is a Content-Length header variable. I of course want it to leave the JPEG frames intact that may have piled in after the HTTP response in the receive queue until I start requesting them (that is, I don't want it including any of the JPEG frames in the HTTP response to my streaming request command until I ask for them using a successive read call).
Is there a method that I can call on a TIdTCPClient that will retrieve completely a typical HTTP response with body content, and nothing else? I thought about using SendCmd() and checking the LastCmdResult property (type: TIdRFCReply) for the response, but I can't tell from the Indy documentation if it retrieves the response body content too if there is a Content-Length header variable as part of the response it returns, nor can I tell if it leaves the rest of the receive queue after the response intact.
What is the best way to accomplish this mixed mode interaction with an HTTP web server that pushes out a stream of JPEG frames right after you make the HTTP request to start streaming?
Also, if there is a clever way to have Indy split the frames using the JPEG frame WINBONDBOUDARY delimiting string, rather than accumulating blocks of data and parsing them out myself, please share that technique.
The correct way to read an HTTP response is to first read the CRLF-delimited response headers line-by-line until a blank line is encountered, aka a CRLF+CRLF sequence, then you can use those headers to decide how to read the remaining response data. The headers will tell you not only what kind of stream is being sent (via the Content-Type header), but also how the data is being framed (Content-Length, Transfer-Encoding: chunked, something specific to the particular Content-Type, etc).
To receive the headers, you can use the connection's Capture() method, setting its ADelim parameter to a blank string.
How you read the remaining data afterwards depends on the actual formatting/framing of the stream. Without knowing exactly what kind of stream you are receiving, there is no way to advise you how best to read it, as there are several different types of streaming protocols used by HTTP servers, and most of them are not standardized. Provide that information, then I/we can show you how to implement it with Indy.
You cannot use SendCmd() as the HTTP protocol does not format its responses in a way that is compatible with that method.

How can I read my application’s CFNetwork-level User-Agent?

I want to programmatically retrieve my application’s User-Agent string. (Note: not the UA of a UIWebView in my application; the UA for NSURLConnection-based HTTP requests.)
There’s lots of guides on how to read an application's UIWebView User-Agent, but none on how to get at the <appname>/1.0 CFNetwork/456.23 string that CFNetwork stuffs inside its HTTP requests. There’s API for CFHTTPMessage to copy out all header fields, but I only have an NSURLRequest and an NSURLResponse, and these are unbridged opaque types. Help!
(Some good background reading: Changing the userAgent of NSURLConnection mentions the format that I want to get at. What HTTP User-Agent does my iOS program advertise itself as? does as well.)
Completely twisted: create a local socket on port 80 and make a local request (to yourself), read the HTTP headers.

Send URL encoded data instead of JSON

Is it possible to POST "url encoded" parameters to a remote web service instead of JSON or XML ?
My rails application consumes a web service which takes URL encoded parameters (content-type: application/x-www-form-urlencoded) in POST requests and give JSON answers.
Is this kind of RESTful services common ?
When you make a hit to a JSON or XML web service using Ajax then the parameters are just getting encoded as either GET or POST, and is typically sent using the application/x-www-form-urlencoded content type anyway (see http://api.jquery.com/jQuery.ajax/ for an example specific to jQuery).
So, basically, yes, it is possible to send data in any format (JSON, XML, BSON etc.) in this manner.

Resources