我正在尝试使用Prototype/AJAX访问Web服务并遇到一个我无法弄清楚的错误:似乎当我向服务器发出请求时,我的请求被解释为OPTIONS而不是GET请求(反过来抛出一个501 - 未实现的错误,因为服务器只根据我的理解允许GET请求Access-Control-Request-Method:).我在AJAX /请求公式中遗漏了可能导致此错误的内容吗?我在这里阅读了一些CORS/preflighted请求,但我不确定当我的代码看起来合规时它是如何应用的...
这是相关的AJAX请求:
function fetchMetar() {
var station_id = $("station_input").value;
new Ajax.Request(REQUEST_ADDRESS, {
method: "get",
parameters: {stationString: station_id},
onSuccess: displayMetar,
onFailure: function() {
$("errors").update("an error occurred");
}
});
}
Run Code Online (Sandbox Code Playgroud)
这是我从Chrome获得的错误和相关请求信息:
Request URL:http://weather.aero/dataserver_current/httpparam?
dataSource=metars&requestType=retrieve&format=xml&hoursBeforeNow=3
&mostRecent=true&stationString=&stationString=KSBA
Request Method:OPTIONS
Status Code:501 Not Implemented
Request Headers
Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Access-Control-Request-Headers:origin, x-prototype-version, x-requested-with, accept
Access-Control-Request-Method:GET
Connection:keep-alive
Host:weather.aero
Origin:http://domain.com
Referer:http://domain.com/.../...html
Run Code Online (Sandbox Code Playgroud)
我能在这里俯瞰什么?为什么Chrome会将请求作为OPTIONS而不是GET发送?当Chrome吐出Access-Control-Request-Headers:信息时,这些信息是否仅是请求中允许的唯一标头?
谢谢!
我遇到了一个问题,设置basic.qos为1没有达到预期的效果 - 大量消息仍然被推送给我的消费者。
我的代码看起来有点像这样:
Channel channel = getChannel("pollQueuePassive"); // from our own channel pool implementation
try{
channel.queueDeclarePassive(queue.name);
} catch (IOException e){
channel = getChannel("pollQueueActive");
channel.queueDeclare(queue.name, true, false, false, null);
}
channel.basicQos(1);
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume(queue.name, autoAck, consumer);
while (!stopPolling()) {
try{
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
String message = new String(delivery.getBody());
boolean workResult = doWork(message);
if(!autoAck) {
if(workResult)
channel.basicAck(delivery.getEnvelope().getDeliveryTag(), true);
else
channel.basicNack(delivery.getEnvelope().getDeliveryTag(), false, true);
}
} catch (InterruptedException e) {}
}
closeConnection();
Run Code Online (Sandbox Code Playgroud)
一旦我开始以这种方式从队列中消费,队列中的所有消息(在某些情况下最多 20,000 条)几乎会立即传递给消费者。由于我想同时将队列中的消息分发给数十个消费者,这种行为显然是不可取的。我玩过移动我的 …