In Actionscript 2 how can I get 302 redirect from a XML object? - actionscript

I am working on an Actionscript 2 project - trying to use the XML object to find a url which is returned as a 302 redirect. Is there a way to do this in actionscript 2?
code:
var urlone:XML = new XML();
urlone.load("http://mydomain.com/file.py");
urlone.onLoad = function (success) {
trace("I want to print the 302 redirect url here, how do I access it?");
};

I don't think it's possible from AS2, I think the browser will redirect to the new URL automatically & just return the data from that URL. It may be possible in AS3, they added several new features such as reading HTTP headers and so on.
Perhaps what you should do is instead of returning a 302 redirect, just return the URL as a text string. Then it would be easy to read from within Flash, just use .onData instead of .onLoad so it doesn't try to parse the XML.

I don't think it's possible (at least using the XML class). It has an onHTTPStatus event handler but it seems that even with that, you'll only be able to access the status code and nothing else.

Related

Returning a 201 (Created) with location header in Vapor 3

I am trying to implement a REST-ful API using Vapor 3, and I'd prefer to use what seems like a fairly standard creation pattern in other web frameworks: I'd like the entity creation controllers to return a 201 Created response status, with a Location response header that contains the full URL of the newly-created resource.
All of the Vapor 3 documentation I can find shows a create pattern that instead returns a 200 OK status, and includes the full resource in the response body. But I can't find any examples that use a 201 response even though that tends to be the more standard REST-ful API approach in my experience.
I have found that I can manually create a 201 response in my controller, and I assume there's a way to set arbitrary headers in that response. If so, is there a convenient way of getting the full URL of the resource I've just created so that I can set a Location header in the response?
I'm sure there are ways I can "brute force" this to get what I want but I am hoping that Vapor defines an idiomatic way to do this, much like the Java and Rails frameworks I've used provide.
Since you are manually creating a response, you are right, adding an arbitrary header is simple.
I assume you are following the standard CRUD route structure, so if you have a User model, you have the following routes:
POST /users
GET /users/:user
PATCH /users/:user
DELETE /users/:user
The important part here is that we know that the URL to get the user is the URL to create a user, plus the user's ID. If this is the case, we can create a location header like this:
user.save(on: req).map { user in
let http = HTTPResponse(...)
let location = req.http.url.path + "/" + user.id.description
http.headers.replaceOrAdd(name: "Location", value: location)
return Response(http: http, container: req)
}

Jmeter: Dynamic URL encrypted

I'm working on a test plan with Jmeter.
The issue is that I can't retrieve the URL link as he is managed dynamically.
The URL has the following format:
localhost\blablabla?PATHPARAM=qzflh%2FGJHBGDCV%GROPJHVFFFDDFGGCFD%JJYTGVFRTVFGGFF%JUYGBG
I already try to search the value of PATHPARAM in the previous requests to retrieve it using regular expression extractor but I didn't find it.
It seems that this url is generated inside a javascript code but the way to extract it is unknown for me, inside the js code I find the value : var url = actionName + "?" + params ;
Is that any way to catch the content or the var url in Jmeter, else have you any other solution to solve this issue with this dynamic URL.
Many thanks in advance for your help.
I can see 2 possible options:
If you are being redirected to this URL automatically (you might need to play with Redirect Automatically and Follow Redirects boxes in the HTTP Request sampler
If this is the case - you should be able to get it using the following Regular Expression Extractor configuration
If you need to replicate the logic of this param variable calculation - you can attempt to do it using JSR223 PreProcessor which can execute arbitrary JavaScript code

ASP.NET WEB API 406 error:for POST request using Media format

I am very new to web api stuff:
I am getting an error
406: Not Acceptable
error message in asp.net web api rest service.
In my rest service I’m using media format for my customized XML output, to get customized output.
I’m registering my formatted media in Global.asax page.
GlobalConfiguration.Configuration.Formatters.Clear();
GlobalConfiguration.Configuration.Formatters.Add(new mynewformat());
all my methods are post methods with typed object as parameter and parameters are accepts from body.
Whenever I try to test the service… Getting 406: Not acceptable error message.
can anyone please help me ... what could be the reason for this....???
I did notice couple of interesting points here...
If I’m commenting below line then I’m getting 200 (OK) status code (which is fine.)... but format is not applying to output.
GlobalConfiguration.Configuration.Formatters.Clear();
If i'm removing parameters in my service method.. Then its working
fine..
I request everyone.. Please guide me what could be the reason/work around/solution/fix..for this issue.
Note:I don't want accept parameters from URI so i made it to accept from frombody only.
Thanks.
There is a lot more to implementing a custom format than just adding it to the configuration formatters. It starts with having to change the media-type header to a new custom type of your choosing (like "application/myNewFormat") for all requests, for the client. On the back end, you have to implement a new MediaTypeFormatter that can handle the serialization. This involves a bit more of code.
A good example of this resides here, it can easily be stripped to boiler-plate code:
http://www.codeproject.com/Articles/559378/Implementing-Custom-Media-Formatters-in-ASP-NET-We

Get current fragment in Route, ASP.net MVC

Is there away to get the current fragment from a route that was issued via action link. This is how I am getting the action from the route.
string currentAction = requestContext.RouteData.Values["action"] as string ?? "index";
Can I do something similar to this?
string currentFragment = requestContext.RouteData.Values["Fragment"] as string ?? "";
No, you can't do anything like this. The fragment (everything that follows the # sign in an url) is never sent to the server by the browser, so the sole fact of talking about getting the url fragment server side simply doesn't make sense.
So if you have the following url: http://example.com/foo/bar?key1=value1#abc the server will never be able to fetch abc simply because the client will never send it.
As it has already been pointed out that is not possible. Document fragments (the string after the hash as you call it) are intended for the browsers only to correctly position the viewport. They have no meaning for the server and therefore are not transmitted there.
There is however a workaround you can use. Repeat the fragment as part of your url to make it accessible for the server.
Look at the permalink to the answers in this question. For instance, the link to my answer looks like this:
http://stackoverflow.com/questions
/6285833/get-current-fragment-in-route-asp-net-mvc/6286097#6286097
See how the value 6286097 is duplicated as the last route parameter. It's intentional. You can use this technique as well.
P.S. The fragment must point to an identifier in the document (id of some HTML element). At least in XHTML only identifiers work as fragments. Valid ids may not begin with a digit therefore instead of #6286097 use something like #answer-6286097.
P.S.#2. Do not use any JavaScript trickery to get around this limitation. Basic site functionality and design must work without JavaScript - don't listen to anyone who tells you otherwise. Fragments obviously belong to the basic tool box. Use JavaScript only for advanced interactivity.
I have a workaround for you, but first of all lets get more into the problem.
The strings after the hash symbol which are called Fragment values are not query parameters but they are strings to be read by the client-side (living in the browser) and the server cannot read them because they are not sent to the server by the browser.
Some authentication providers like Google and Azure send the access token as Fragment value for security reasons so that they are not transferred over the internet after they get sent as direct response from the authentication provider.
The only way you can come around that is to use javascript to convert the fragment values to query parameters by replacing the '#' with '?' and redirecting to the endpoint in your server controller.
I suppose the easiest way is to handle all that from server, meaning you get get the request in server, send a javascript code to the browser on the fly, that replaces the '#' into '?' and redirects to your second endpoint which reads the token as strong parameter.
Here how you can do it in ASP.NET Core 3.1:
[AllowAnonymous]
[HttpGet("authredirect")]
[Produces("text/html")]
public virtual ContentResult ConvertUrlFragmentToQueryParamThenRedirect()
{
return Content("<html><script>window.location.href=window.location.href.replace('#', '?').replace('authredirect', 'authparams')</script></html>", "text/html");
}
[AllowAnonymous]
[HttpGet("authparams")]
public virtual void GetAccessToken([FromQuery] string access_token)
{
// now you have your access token server side here
}
Please remember to set your redirectUrl to the correct one, in this case 'YOUR REDIRECT URL/authredirect'.

HTTP HEAD Request and System.Web.Mvc.FileResult

I'm using BITS to make requests to a ASP.NET MVC controller method named Source that returns a FileResult. I know the type FilePathResult uses HttpResponse.TransmitFile, but I don't know if HttpResponse.TransmitFile actually writes the file to the response stream regardless of the request type.
My question is, does FileResult only include the header information on HEAD requests, or does it transmit the file regardless of the request type? Or, do I have to account for HEAD requests myself?
The result is forced to react on a request by YOUR ACTION CODE. If you do not do anything special on different request types (e.g. [HttpGet]-Attribute, HttpMethodConstraints in the Route, etc...) The file is just written to the response stream.

Resources