标签: http-get

HTTP状态405 - 此URL不支持HTTP方法GET

我有以下servlet:

public class MyServlet extends HttpServlet {

    private static final long serialVersionUID = 16252534;
    private static int ping = 3000;
    private Thread t;
    private static boolean shouldStop = false;

    @Override
    public void init() throws ServletException {
        super.init();

        t = new Thread(new Runnable() { 
            @Override
            public void run() {
                while(!shouldStop) {
                    System.out.println("Now:" + System.currentTimeMillis());
                    try {
                        Thread.sleep(ping);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
        t.start();

    }
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {
        super.doGet(req, …
Run Code Online (Sandbox Code Playgroud)

servlets http-get http-status-code-405

22
推荐指数
1
解决办法
3万
查看次数

添加'System.Web.Http'命名空间时,找不到类型或命名空间名称'HttpGet'

我在MVC中有一个问题.

目前我在MVC工作,版本是MVC4.我有2个ActionResult方法,见下文

[HttpGet]
 public ActionResult About()
        {
            ViewBag.Message = "Your app description page.";

            return View();
        }

 [HttpPost]
 public ActionResult About(ModelName ccc)
        {
            ViewBag.Message = "Your app description page.";

            return View();
        }
Run Code Online (Sandbox Code Playgroud)

我们需要[HttpPost][HttpGet]属性的using System.Web.Mvc;命名空间 .所以我在控制器中添加了命名空间.但我需要在我的控制器中为httpsresponseexpection错误处理添加另一个命名 空间.我在命名空间中添加了.这时候不行.using System.Web.Mvc;using System.Web.Http;System.Web.Mvc;

我收到此错误:无法找到类型或命名空间名称'HttpGet'.为什么?HttpGet的System.Web.Mvc和System.Web.Http之间的任何关系?

c# asp.net-mvc http-get http-post

21
推荐指数
1
解决办法
3万
查看次数

用于GET请求的ASP.NET MVC的自定义模型Binder

我已经创建了一个自定义的MVC Model Binder,每次HttpPost进入服务器都会调用它.但不会被HttpGet要求提出要求.

  • 我的自定义模型绑定器是否应该被调用GET?如果是这样,我错过了什么?
  • 如果没有,我怎么可以编写自定义代码处理QueryStringGET请求?

这是我的实施......

public class CustomModelBinder : DefaultModelBinder
{
   public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
   {
      // This only gets called for POST requests. But I need this code for GET requests.
   }
}
Run Code Online (Sandbox Code Playgroud)

Global.asax中

protected void Application_Start()
{
   ModelBinders.Binders.DefaultBinder = new CustomModelBinder();
   //...
}
Run Code Online (Sandbox Code Playgroud)

我已经研究过这些解决方案,但它们并不能满足我的需求:

  • 坚持复杂的类型 TempData
  • 使用默认绑定器构建复杂类型(?Name=John&Surname=Doe)

备注答案

感谢@Felipe的帮助.为了防止有人与之斗争,我学到了:

  • 定制模型绑定CAN用于GET请求
  • CAN使用DefaultModelBinder
  • 我的想法是动作方法必须有一个参数(否则会跳过模型绑定器的 …

c# asp.net-mvc http-get custom-model-binder

19
推荐指数
1
解决办法
1万
查看次数

如何正确使用axios params与数组

如何在查询字符串中向数组添加索引?

我尝试发送这样的数据:

axios.get('/myController/myAction', { params: { storeIds: [1,2,3] })
Run Code Online (Sandbox Code Playgroud)

我得到了这个网址:

http://localhost/api/myController/myAction?storeIds[]=1&storeIds[]=2&storeIds[]=3
Run Code Online (Sandbox Code Playgroud)

所以,我应该得到这个网址:

http://localhost/api/myController/myAction?storeIds[0]=1&storeIds[1]=2&storeIds[2]=3
Run Code Online (Sandbox Code Playgroud)

我应该在我的params选项中添加什么来获取此URL?

javascript arrays http-get axios

18
推荐指数
4
解决办法
2万
查看次数

在 JavaScript 中发送带有正文的 GET 请求 (XMLHttpRequest)

我必须与从 GET 请求正文中获取参数的 API 进行交互。我知道这可能不是最好的主意,但它是 API 的构建方式。

当我尝试使用 构建查询时XMLHttpRequest,看起来负载根本没有发送。您可以运行它并查看网络选项卡;请求已发送,但没有正文(在最新的 Chrome 和 Firefox 中测试):

const data = {
  foo: {
    bar: [1, 2, 3]
  }
}
const xhr = new XMLHttpRequest()
xhr.open('GET', 'https://my-json-server.typicode.com/typicode/demo/posts')
xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8')
xhr.send(JSON.stringify(data))
Run Code Online (Sandbox Code Playgroud)

诸如 axios 之类的库是基于 XMLHttpRequest 构建的,因此它们也无法正常工作...

有没有办法在 JavaScript 中实现这一点?

javascript ajax rest xmlhttprequest http-get

18
推荐指数
1
解决办法
2万
查看次数

HttpGetAttribute 构造函数中的“name”属性是什么?

当我使用HttpGet(...)时,智能感知告诉我,除了第一个参数(即pattern )之外,我还有nameorder。虽然后者对我来说是显而易见的,但我有点不确定参数名称的用途

转到文档,我看到HttpGet的构造函数仅声明一个参数。这让我很困惑,我怀疑我错过了一些东西,或者使用了框架的版本而不是核心,或者其他东西。

c# routes http-get .net-core asp.net-core

18
推荐指数
3
解决办法
2万
查看次数

没有源代码可用于类型:GWT编译错误

我试图在我的GWT应用程序中通过servlet获取请求.在编译代码时,我收到了这些错误.

[ERROR] Line 16: No source code is available for type org.apache.http.client.ClientProtocolException; did you forget to inherit a required module?
[ERROR] Line 16: No source code is available for type org.apache.http.ParseException; did you forget to inherit a required module?
[ERROR] Line 16: No source code is available for type org.json.simple.parser.ParseException; did you forget to inherit a required module?
Run Code Online (Sandbox Code Playgroud)

我该怎么做才能消除这些错误?GWT不支持这些类吗?

以下是我正在使用的代码

public String getJSON() throws ClientProtocolException, IOException, ParseException{
    HttpClient httpclient = new DefaultHttpClient(); 
    JSONParser parser = new JSONParser();
    String url = …
Run Code Online (Sandbox Code Playgroud)

java gwt json http-get httpresponse

16
推荐指数
3
解决办法
4万
查看次数

如何将响应从http.get映射到Angular 2中的类型化对象的新实例

我试图了解如何使用Angular 2中的http.get和Observables将服务调用的结果映射到对象.

看看这个Plunk

在方法getPersonWithGetProperty中,我期望返回一个类型为PersonWithGetProperty的Observable.然而!我无法访问属性fullName.我想我必须创建PersonWithGetProperty类的新实例,并使用类构造函数将响应映射到这个新对象.但是你如何在方法getPersonWithGetProperty中做到这一点?

import {Injectable} from '@angular/core';
import {Http, Response} from '@angular/http';
import {Observable} from 'rxjs/Rx';

export class PersonWithGetProperty {
  constructor(public firstName: string, public lastName: string){}

  get fullName(): string {
    return this.firstName + ' ' + this.lastName;
  }
}

@Injectable()
export class PersonService {
    constructor(private http: Http) {
    }

    getPersonWithGetProperty(): Observable<PersonWithGetProperty> {
        return this.http.get('data/person.json')
         .map((response: Response) => <PersonWithGetProperty>(response.json()));
    }
}
Run Code Online (Sandbox Code Playgroud)

http-get observable rxjs typescript angular

16
推荐指数
1
解决办法
4万
查看次数

Response.Redirect将数据POST到ASP.NET中的另一个URL

我想将响应重定向到另一个URL,同时它的HTTP头中包含一些POST数据.

// Inside an ASP.NET page code behind:
Response.Redirect("http://www.example.com/?data=sent%20via%20GET");
// This will sent data to http://www.example.com via GET.
// I want to POST this data to http://www.example.com instead.
Run Code Online (Sandbox Code Playgroud)

如何在ASP.NET中执行此操作?

asp.net response.redirect http-get http-post

15
推荐指数
2
解决办法
4万
查看次数

Microsoft Edge的URL长度限制

有人知道Microsoft Edge的URL长度限制吗?如您所知,Internet Explorer对URL长度有限制,最大长度为2048. Edge如何?我猜,它现在应该已经消失了......

browser http-get microsoft-edge

15
推荐指数
2
解决办法
8045
查看次数