我正在编写一个Android 2.2应用程序,它将json严格性发布到ReSTfull Web服务.
Fiddler按预期调用具有相同Json返回值的Web服务,并按预期返回具有相同Json返回值的aspx Web应用程序.
当我查看服务器日志时,我可以看到服务器正在响应具有307重定向的初始POST动词,然后立即响应GET和405错误.
Fiddler和aspx应用程序使用307重定向记录POST,然后立即另一个POST和200 OK.
到底是怎么回事?
这是主要活动:
package com.altaver.android_PostJson2;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class PostJson extends Activity {
private static final String TAG = "MainActivity";
private static final String URL = "http://web2.altaver.com/sdz/avReSTfulLogin1";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
JSONObject jsonObjSend = new JSONObject();
try {
jsonObjSend.put("Pass", "sz");
jsonObjSend.put("User", "szechman");
Log.i(TAG, jsonObjSend.toString(2));
} catch (JSONException e) {
e.printStackTrace();
}
JSONObject …Run Code Online (Sandbox Code Playgroud) 我有一个带有整数字段的模型,该整数字段将在用户单击时增加,例如“投票”按钮。
该按钮仅显示在详细视图上。要增加投票数,它会发送一个ajax POST。问题在于,即使在执行视图之前,django也会返回405(不允许的方法)错误。是什么原因造成的?
这是我的代码:
views.py(不会执行)
@require_POST
def vote_proposal(request, space_name):
"""
Increment support votes for the proposal in 1.
"""
prop = get_object_or_404(Proposal, pk=request.POST['propid'])
proposal_form = VoteProposal(request.POST or None, instance=prop)
if request.method == "POST" and request.is_ajax:
if proposal_form.is_valid():
vote = proposal_form.cleaned_data['propid']
vote.support_votes += 1
vote.save()
msg = "The vote has been saved."
else:
msg = "The vote didn't pass validation."
else:
msg = "An error has ocurred."
return HttpResponse(msg)
Run Code Online (Sandbox Code Playgroud)
jQuery代码:
<script type="text/javascript">
function upvote(proposal) {
var request = $.ajax({
type: "POST", …Run Code Online (Sandbox Code Playgroud) 我正在做一个关于appengine的应用程序,它在那里工作得很好.我在facebook canvas URL上有应用程序的URL http://xx.appspot.com/yyy/(带尾随斜杠),当从http调用应用程序时:我得到了//apps.facebook.com/appname
405不允许的方法此资源不允许使用POST方法.
class MainHandler(webapp2.RequestHandler):def get(self):#do stuff here def post(self):pass
app = webapp2.WSGIApplication([('/ yyy /',MainHandler),('/',anotherHandler),
],debug = True)
注意:appengine日志中没有这样的错误.
我试图将请求转发到另一个接受 GET 请求的 Spring 控制器,但它告诉我不支持 POST。这是我的第一个控制器方法的相关部分,它确实接受 POST 请求,因为我将它用于登录功能。
@RequestMapping(value = "/login", method = RequestMethod.POST)
public String login(@ModelAttribute("administrator") Administrator administrator,
Model model) {
// code that's not germane to this problem
return "forward:waitingBulletins";
}
Run Code Online (Sandbox Code Playgroud)
这是我尝试转发的方法。
@RequestMapping(value = "/waitingBulletins", method = RequestMethod.GET)
public String getWaitingBulletins(Model model) {
// the actual code follows
}
Run Code Online (Sandbox Code Playgroud)
这是我的浏览器中的错误消息。
HTTP Status 405 - Request method 'POST' not supported
--------------------------------------------------------------------------------
type Status report
message Request method 'POST' not supported
description The specified HTTP method is not allowed for …Run Code Online (Sandbox Code Playgroud) 我正在研究iOS UDID检索脚本,遗憾的是陷入了一个小问题.您可能知道,要检索iOS UDID,用户必须在iOS设备上安装配置文件.之后,设备响应定义到配置文件中的链接.如果用户直接打开检索链接,则不允许使用Error 405 Method.与以下链接相同:http: //get.udid.io/retrieve/和http://license.if0rce.com/connect/retrieve
/retrieve/index.php中的代码是:
<?php
$data = file_get_contents('php://input');
file_put_contents("data.txt", $data);
?>
Run Code Online (Sandbox Code Playgroud)
我可以添加以下内容来设置自定义错误:
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
header("HTTP/1.0 405 Method Not Allowed");
exit(); }
Run Code Online (Sandbox Code Playgroud)
但这不是专业的方式.我希望用户得到的错误与上述链接完全相同.
有任何想法吗?
感谢您的帮助 :)
我有一个每日 cron 来处理我的应用程序中的一些重复事件,我不时注意到日志中弹出一个奇怪的错误。除其他外,cron 会对一些代码进行验证,并且它使用运行在同一服务器上的 web 应用程序,因此验证请求是通过POST带有一些数据的请求发出的。
url = 'https://example.com/validate/'
payload = {'pin': pin, 'sku': sku, 'phone': phone, 'AR': True}
validation_post = requests.post(url, data=payload)
Run Code Online (Sandbox Code Playgroud)
所以,这会产生实际的请求,我会记录响应。有时,最近高达 50% 的请求,响应包含来自 nginx 的以下消息:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>405 Method Not Allowed</title>
<h1>Method Not Allowed</h1>
<p>The method GET is not allowed for the requested URL.</p>
Run Code Online (Sandbox Code Playgroud)
因此,实际请求是使用GET方法发出的,而不是代码中指示的POST。在 nginx 中,access.log我可以看到该条目:
123.123.123.123 - - [18/Feb/2015:12:26:50 -0500] "GET /validate/ HTTP/1.1" 405 182 "-" "python-requests/2.2.1 CPython/2.7.6 Linux/3.13.0-37-generic"
Run Code Online (Sandbox Code Playgroud)
该应用程序的 uwsgi 日志显示了类似的内容: …
我在 nginx 使用 Http POST 方法下载 excel 文件时遇到问题。事实上,我收到状态代码:405 不允许。
这是我的配置
upstream backend{
server localhost:9090;
server localhost:9091;
server localhost:9092;
server localhost:9093;
}
server {
listen 8887;
server_name localhost;
location / {
proxy_pass http://backend;
proxy_next_upstream error timeout http_404;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
}
}
Run Code Online (Sandbox Code Playgroud)
我怎么解决这个问题。
先感谢您。
我有简单的控制器代码,如:
// UserController.groovy
class UserController {
static allowedMethods = [
signIn: 'GET',
authenticate: 'POST',
signOut: 'POST',
register: 'GET',
save: 'POST'
]
// ... code omitted
def register() { }
def save() {
render 'ok'
}
}
Run Code Online (Sandbox Code Playgroud)
报名表格:
<!-- register.gsp -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="layout" content="main" />
<title>Withme: Register</title>
</head>
<body>
<g:form mapping="register">
<!-- Code omitted -->
<g:actionSubmit value="Register" />
</g:form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
和网址映射:
//UrlMappings.groovy
class UrlMappings {
static mappings = {
name register: '/register'(controller: 'user') …Run Code Online (Sandbox Code Playgroud) 我试图让 OPTIONS 请求与 django 一起工作,但我目前只得到 405。我在这里得到的答案是服务器不处理 OPTIONS 请求。
这是处理请求的视图:
from django.views.generic import View
from piston.utils import coerce_put_post
class TheView(View):
@staticmethod
def find_stuff(params):
...
@staticmethod
def do_stuff(params):
...
@staticmethod
def do_other_stuff(params):
...
@staticmethod
def delete_some_stuff(params):
...
@method_decorator(staff_member_required)
def get(self, request, id):
result = self.find_stuff(id)
return JsonResponse(result)
@method_decorator(staff_member_required)
def post(self, request):
result = self.do_stuff(request.POST)
return JsonResponse(result)
@method_decorator(staff_member_required)
def put(self, request, id):
coerce_put_post(request)
result = self.do_other_stuff(id,request.PUT)
return JsonResponse(result)
@method_decorator(staff_member_required)
def delete(self, request,id):
result = self.delete_some_stuff(id)
return JsonResponse(result)
Run Code Online (Sandbox Code Playgroud)
我正在使用 jQuery 的 $.ajax() …
我正在尝试通过 javascript 删除 Google 联系人。根据我定义的 Google Contacts api v3:
scope to https://www.google.com/m8/feeds
Run Code Online (Sandbox Code Playgroud)
并经过身份验证的用户,并获得了 access_token。根据此页面上的 v3 文档,尝试删除这样的联系人:
$.ajax({
url: 'https://www.google.com/m8/feeds/contacts/default/full/temp123info@gmail.com?access_token=ya29.AHES6ZQoqUgoYmDzXyo-WsSlKv1-_2D_HzmXuH-wBuTR3e1ADxO0VWM',
type: 'DELETE',
success: function(res)
{
console.log(res);
},
error: function(error)
{
console.log(error);
}
});
Run Code Online (Sandbox Code Playgroud)
收到此错误:
"NetworkError: 405 Method Not Allowed - https://www.google.com/m8/feeds/contacts/laiquedaudpota43@gmail.com/full/temp123info@gmail.com?access_token=ya29.AHES6ZQoqUgoYmDzXyo-WsSlKv1-_2D_HzmXuH-wBuTR3e1ADxO0VWM"
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激。谢谢。
django ×2
nginx ×2
android ×1
api ×1
django-views ×1
facebook ×1
grails ×1
grails-2.0 ×1
httpclient ×1
ios ×1
javascript ×1
json ×1
php ×1
post ×1
python ×1
spring-mvc ×1
udid ×1
url-routing ×1
uwsgi ×1
voting ×1