{"message":"Method Not Allowed"} on echo framework - go

When I enter the URI http://localhost:9000/dashboard or any other URI that uses the http POST method I always get errors, this is my handler
e.POST("/dashboard", controller.Dashboard)

When you type an URL into a browser, it will send a GET. To handle it you must use e.GET("/dashboard", controller.Dashboard) in your application.
If the page contains a form that submits a POST, you must handle both GET and POST. Both can be mapped to controller.Dashboard if desired, but it is normally easier to use different handlers.

Related

Cypress: Test non-XHR request caused by submitting POST form

I am testing Vue application. In some cases my application have to submit(not just after click submit button but programmatically) POST form and redirect to 3rd party server with some body parameters. Like in best practice written I am trying to avoid of using redirect to real server.
For my certain test it will be sufficient to just make sure that request was sent with certain parameters, but I don't now how to catch this body request parameters for assertion, because cypress does not allow to stub non-XHR requests and I can't do like this:
cy.route('POST', '/posts').as('post')
cy.get("#post").should(req => {
// check body params
});
I also thought about stub vue component method to intercept form submitting, but it only seems to work with global objects like Math.
I truly appreciate any new ideas how to test functionality like this.
Since Cypress 5.1 you can stub other requests type using cy.route2()(https://docs.cypress.io/guides/references/changelog.html#5-1-0).

Windows forms navigate webrowser method not available?

I try to navigate to a url and send a new http header with phalanger but when I use the navigate method it gives me an error message there is no method available (even with overload and so). How can I send my own http header? Example:
This dosesn't work:
this->browser->Navigate(new \System\Uri($url),"_self",null, $authHeader);
This works (but it navigates only to the website w/o sending my header:
this->browser->Navigate(new \System\Uri($url),$authHeader);
Edit: This works, too, and is the more correct approach but I want the thing with the additional header!!!
this->browser->Navigate(new \System\Uri($url));

How to set the default serializer in ASP.NET Web API?

I'm currently watching a video course about ASP.NET Web API. When a controller gets called, the data gets returned in JSON by default. I was just wondering, because when I copy this sample project from the video, I get XML.
The frustration is big, please help me to solve this.
I'm pretty new to ASP.NET Web API, so please bear with me.
UPDATE
The controller doesn't contain special code. It's the simple code, which gets generated from the API Controller with empty read/write actions template.
ASP.NET WebAPI comes with built-in content negotitation therefore the format of the return value is determined by the request itself - more specifically by the Accept/Content-Type headers (depending on which ones are present, Accept header appears to be favoured over the Content-type).
I assume you're viewing the results in a browser and by default it's probably asking for application/xml. You will need to toy around with some settings/developer tools on the browser and force it to send Content-Type: application/json to get the correct response (assuming your returning HttpResponseMessage).
in Global.asax: add the line:
GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
It'll look like this.
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
BundleTable.Bundles.RegisterTemplateBundles();
GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
}
James is close, but the content negotiation actually uses the [Accept] header,
not [Content-Type]
As with nearly everything else in MVC, you can override the content negotiation components to ensure the desire content is returned
W3c clearly states-
14.1 Accept
The Accept request-header field can be used to specify certain media types which are acceptable for the response.
-and-
14.17 Content-Type
The Content-Type entity-header field indicates the media type of the entity-body sent to the recipient or, in the case of the HEAD method, the media type that would have been sent had the request been a GET.
This page headers is very useful to understand request/response negotiation.

CakePHP redirect method not redirecting

I am trying to redirect to a new page using CakePHP redirect method but for some reason the redirect is not working. The code I am using to redirect is
public function update_sticky_postition_in_db()
{
$this->autoRender = false;
... // Save info to database
$this->redirect(array('action' => 'tool'));
}
Where tool is the name of the view I am tring to redirect to. To try and speed the process of finding the problem I have checked few things and think I have found the cause of the problem. Basically I am trying to redirect to the view that is currently active which I think is part of the reason why it is not redirecting. I have read that it might have something to do with caching of the page but I am not sure how to solve that issue.
Also when using firebug I can see the redirect is sending a GET request but after that nothing is happening. Do I have to do something with the GET request or should Cake handle that for me. Also I have checked the URL of the GET and it is correct.
It is located within the controller with the correct name as I can view the original tool page.
Also the update_sticky_postition_in_db() method does not have a view (hence why the auto render is set to false), its intended purpose is to update a row in the database from an ajax call.
From your post it seems you're firing the update_sticky_postition_in_db() using ajax call, so that the redirection will not work.
You can do redirection using JavaScript within ajax success method.
In order to do that, you may send some json_encode() message from you above method and checking that status within ajax success method you can do a redirect using window.location.

What is difference between Response.Redirect("http://url") and Response.Write("REDIRECT=http://url")?

I'm working on ASP.NET MVC3 with C#.
What is difference between Response.Redirect("http://www.google.com"); and Response.Write("REDIRECT=http://www.google.com");?
The difference is that the first will replace the response with a redirection page and end the execution, while the second will just write the text to the response stream and continue with creating the rest of the page.
Response.Redirect() sets an HTTP 302 header along with the URL to be redirected to.
Response.Write("REDIRECT=http://www.google.com"); will write that string to the response body, as in that redirect text would be appended to the HTML of your web page.
This will create the correct full HTTP Header for you:
Response.Redirect("http://www.google.com");
You have the ability to set or change some paramters for the HTTP Header.
HttpResponse Class
e.g set HTTP Status Code 404 or 500 or in your case 302 for redirect.
e.g set the HTTP Mime-type for jpg
Will write into the Body in your response..like a string output
Response.Write("REDIRECT=http://www.google.com");
The methods in question are quite self explanatory :)
Response.Redirect("http://www.google.com");
The Redirect will redirect you to another page, in the case it will take you to Google's home page.
Response.Write("REDIRECT=http://www.google.com");
The Write method will write a string of text to the web page. In this case it will write the text "REDIRECT=http://www.google.com" to your web page.
Play around with these 2 methods in your web project and see what happens.

Resources