我正在尝试使用HttpUrlConnection执行PURGE,如下所示:
private void callVarnish(URL url) {
HttpURLConnection conn = null;
try {
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod(PURGE_METHOD);
conn.setDoOutput(true);
conn.setInstanceFollowRedirects(true);
conn.setRequestProperty("Host", "www.somehost.com");
conn.connect();
System.out.print(conn.getResponseCode() + " " + conn.getResponseMessage());
}
catch (Exception e) {
log.error("Could not call varnish: " + e);
} finally {
if (conn != null) {
conn.disconnect();
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是我得到了:
08:56:31,813 ERROR [VarnishHandler] Could not call varnish: java.net.ProtocolException: Invalid HTTP method: PURGE
Run Code Online (Sandbox Code Playgroud)
卷曲没有问题:
curl -I -X PURGE -H"主持人:www.somehost.com"someurl
HTTP/1.1 404 Not in cache.
Server: Varnish
Content-Type: text/html; …Run Code Online (Sandbox Code Playgroud) 我加入了一个使用spring框架的项目,所有的调用都是由ajax请求完成的,成功后的重定向是在视图中定义的,并通过隐藏的输入传递给ajax JS函数(所以在每个函数的末尾都返回ModelAndView)在控制器中没有任何影响).我觉得它弄糟了代码我不对吗?我仍然认为这样做是因为他们希望获得使用CRUD映射到post,get,put,delete的restful app的好处,但最终他们失去了从控制器本身重定向的能力.
这可能是一个自我回答的问题,但是我希望你们中的一个人能够指出我声明或者可以推断的任何资源,在HTTP或REST中声明HTTP方法名称时是使用大写或小写字母要求.我看到的大多数示例都以大写字母表示GET,PUT,POST,DELETE,PATCH等,而我假设HTTP方法字段名称不区分大小写 - 例如,"get"同样有效作为"GET".传统上我总是使用大写字母,但我想确定.
在W3C明确声明该方法是区分大小写的,并使用大写字母,但在我的辛苦,我经常遇到用较低的情况下,我认为是不正确的HTTP方法字段值,所以从我的POV,似乎做法,标准在这个问题上有点脱节.
大写是正确的 - 对吗?
我绝对没有找到完全自动进行部分更新的明确方法(可以通过比较数据库和部分对象中的逐字段对象来实现)。
我看到了一些类似的曲目:
MapperServiceheavyResourceRepository哪种save(Map<String, Object> updates, String id)方法的存储库类型是什么copyProperty方法谢谢您,可以使用PATCH方法,但是我看不到实现它的明确方法。
我正在尝试从 POST 重定向到 GET。如何在 FastAPI 中实现这一点?
你尝试了什么?
我已经按照问题#863#FastAPI 的建议尝试了以下 HTTP_302_FOUND、HTTP_303_SEE_OTHER:但没有任何效果!
它总是显示 INFO: "GET / HTTP/1.1" 405 Method Not Allowed
from fastapi import FastAPI
from starlette.responses import RedirectResponse
import os
from starlette.status import HTTP_302_FOUND,HTTP_303_SEE_OTHER
app = FastAPI()
@app.post("/")
async def login():
# HTTP_302_FOUND,HTTP_303_SEE_OTHER : None is working:(
return RedirectResponse(url="/ressource/1",status_code=HTTP_303_SEE_OTHER)
@app.get("/ressource/{r_id}")
async def get_ressource(r_id:str):
return {"r_id": r_id}
# tes is the filename(tes.py) and app is the FastAPI instance
if __name__ == '__main__':
os.system("uvicorn tes:app --host 0.0.0.0 --port 80") …Run Code Online (Sandbox Code Playgroud) 我正在努力让Blueimp jQuery File-Uploader在Windows Server 2008 R2上使用IIS 7.5运行MVC 3.我正在使用HttpHandler来处理上传,这被调用.但HttpHandler永远不会收到文件,也不会收到HttpMethod"POST"或"PUT",总是"OPTIONS".有谁知道这里有什么问题?
我从上传者的失败回调中获得的唯一消息是"错误".
我的JS:
$('#fileupload').fileupload(
{
acceptFileTypes: /(\.|\/)(pdf)$/i,
fail: function (e, data) {
alert("Error: " + data.errorThrown + " Text-Status: " + data.textStatus);
// data.jqXHR;
},
maxNumberOfFiles: 1
/*add: function (e, data) {
data.formData = [{ name: "name1", value: "1" }, { name: "name2", value: "2"}];
data.submit();
},
submit: function (e, data) {
//data.formData = [{ name: "name1", value: "1" }, { name: "name2", value: "2"}];
}*/
}
);
Run Code Online (Sandbox Code Playgroud)
非常感谢您的帮助!
我正在使用Flask开发Web应用程序.其中一个视图应该通过PUT请求接受上传的文件,但是我只能获得POST请求$ curl -F upload=@filename URL才能正常工作.随着PUT请求,如$ curl --upload-file filenname URL在request.filesImmutableMultiDict是空的.我是否在烧瓶中丢失了一些东西或者使用卷曲?
我正在使用Silex框架来模拟REST服务器.我需要为OPTIONS http方法创建uri,但是Application类只提供PUT,GET,POST和DELETE的方法.是否可以添加和使用自定义http方法?
我一直在创建一个WebApi控制器,我正在尝试使用HttpPost请求提交新用户进行注册.这在我的localhost上工作正常,但是当我将它发布到Azure时,我得到一个405方法不允许错误消息:"请求的资源不支持http方法'GET'".
我使用邮递员来检查操作,所以我使用生成代码来查看请求,如下所示:
POST /api/account/register/student HTTP/1.1
Host: www.l3cture.com
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: 27c1b2ab-96ad-4a99-b271-4030402768e7
Run Code Online (Sandbox Code Playgroud)
所以我可以清楚地看到请求是POST.以下是具有其属性的控制器动作代码(我目前已对其进行了简化,因此不会发布任何模型,并且会发生相同的行为)
[HttpPost]
[Route("register/student")]
[AllowAnonymous]
public async Task<IHttpActionResult> PostStudent(/*RegisterStudent model*/)
{
//Implementation of register
return Ok();
}
Run Code Online (Sandbox Code Playgroud)
我已经检查了属性的命名空间,它是System.Web.Http,因此它不会与MVC命名空间混淆.
有趣的是,当我将方法更改为HttpGet,并使用postman对其进行POST时,我收到状态200.这几乎就像HttpPost请求被我的控制器一样对待HttpGet.
我在其他地方使用过HttpPut和HttpDelete,它们都运行良好.
我不确定如何解决这个问题,并且想知道是否有人有任何想法?如果我需要发布更多代码以便澄清,请告诉我.
提前致谢
c# http-method http-status-code-405 asp.net-mvc-4 asp.net-web-api2
我正在使用 Django,并且使用带有 url 的基于类的视图。所以,在 mu 类中,我有以下方法:post、get和。putdelete
例子:
class MyClassView(View):
def get(self, request, id=None):
return HttpResponse('GET request')
def post(self, request):
return HttpResponse('POST request')
def put(self, request, id):
return HttpResponse('PUT request')
def delete(self, request, id):
return HttpResponse('DELETE request')
Run Code Online (Sandbox Code Playgroud)
所以在我的网址中我有类似的内容:
from django.urls import path
from . import views
urlpatterns =[
path('my-class/', views.MyClassView.as_view()),
path('my-class/<int:id>/', views.MyClassView.as_view()),
path('my-class/create/', views.MyClassView.as_view()),
path('my-class/update/<int:id>/', views.MyClassView.as_view()),
path('my-class/delete/<int:id>/', views.MyClassView.as_view()),
]
Run Code Online (Sandbox Code Playgroud)
这很好用!/my-class当我向我发送 GET 请求时,我会得到同样的"GET request"结果;当我向 a 发送 POST 请求时,/my-class/create我会得到"POST request" …
http-method ×10
rest ×4
http ×2
python ×2
blueimp ×1
c# ×1
django ×1
fastapi ×1
file-upload ×1
flask ×1
hibernate ×1
http-put ×1
httphandler ×1
java ×1
java-ee ×1
jquery ×1
php ×1
silex ×1
spring-boot ×1
spring-mvc ×1
spring-rest ×1
symfony ×1
varnish ×1