我启用了django请求处理器
TEMPLATE_PROCESSORS = (
"django.core.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.request",
)
Run Code Online (Sandbox Code Playgroud)
我仍然不需要在模板中请求变量.我要手动传递它.使用django 1.0.2在网上的任何地方它似乎只是关于启用请求处理器..
我也使用RequestContext:
return render_to_response(
'profile.html',
{
'persons':Person.objects.all(),
'person':Person.objects.get(id=id),
'request':request,
},
context_instance=RequestContext(request)
)
Run Code Online (Sandbox Code Playgroud)
没运气
哦,这个新名字是 TEMPLATE_CONTEXT_PROCESSORS
我想用服务器对服务器进行一些API调用HttpURLConnection.但请求不成功,返回:
<error>
<http_status>400 Bad Request</http_status>
<message>Unexpected request Content-Type header ''. Expecting 'application/x-www-form-urlencoded'.</message>
</error>
Run Code Online (Sandbox Code Playgroud)
所以我想检查发送到服务器的"真实"内容是什么.通过真实内容我的意思是确切的HTTP请求.
我有什么想法可以看到这个吗?
编辑: 基于这里的第一个答案,我应该澄清我的问题:我想避免使用像HTTP嗅探器或任何东西的外部程序,我希望有一个功能或属性或任何包含我正在寻找的信息.
如果不是这样,有人知道是否可以手动重建此信息(例如通过调用getRequestMethod()等几个函数)
我经常遇到这个问题,所以我自己也要努力建立这样的功能.只需知道如何:)
我的问题可能更多的是我认为与浏览器相关的问题,但是当我冒险构建一个Web应用程序时,我也想找到答案.
在我的客户端代码中,我正在$.ajax打电话.这篇文章可能需要一段时间才能回复.我所看到的是在一定时间后再次发送请求.
我以为是我$.ajax再次发送它的电话,但不管我在服务器上看到多少次POST请求,我只看到beforeSend一次调用回调.我很确定我的代码不会多次发送它,所以我认为它的浏览器正在重试?
我知道我的服务器收到的请求超过了一次,因为我运行了Wireshark并且可以多次查看发布请求.所以我的假设是这与HTTP有关?即,如果在一定时间内未收到回复,则重新发送请求?
以下是我的电话示例.
$.ajax({
async: false,
type: 'POST',
url: '<%= url_for('importDevice') %>',
data: { device: val },
retryLimit: 0,
//callback
success: function(data) {
alert('calling import');
if ( data == 'nomaster')
{
// Display a warning toast, with a title
toastr.warning('You must set the Master Key first!', 'Warning');
$.ismasterset = false;
//reset the form contents after added
} else
{
$("div#content").html(data);
}
},
beforeSend: function(){
alert('in before send');
}
});
Run Code Online (Sandbox Code Playgroud)
这是所有相关的代码,'retryLimit'没有被使用,我只是没有从我的代码中删除它,是的问题是在我把它放入之前.
使用客户端和服务器的输出进行编辑.
好吧我安装了'Live …
我需要在服务器中间件上获取URL(使用express.js).我使用req.url但是当url从/#some/urlreq.url 开始返回时/...
与req.path... 相同
有没有办法#在express.js 之后获取网址?
我尝试在fetch事件中缓存服务工作者的POST请求.
我用了cache.put(event.request, response),但退回的承诺被拒绝了TypeError: Invalid request method POST..
当我尝试使用相同的POST API时,caches.match(event.request)给了我未定义的内容.
但是当我为GET方法做同样的事情时,它起作用了:caches.match(event.request)因为GET请求给了我一个响应.
服务工作者可以缓存POST请求吗?如果他们不能,我们可以使用什么方法使应用程序真正脱机?
我需要将Microsoft.AspNetCore.Http.HttpRequest从AspNetCore上下文转换为HttpRequestMessage以传递给HttpClient.有没有一种简单的方法来实现这一目标?或者任何实现这一点的提示都会非常有用.
更新 我想将请求转换为消息,但我想更改目标网址,我只想将请求重定向到另一个服务器.
我正在使用 cypress 来测试我们的 Web 应用程序,在某些页面中,有不同的端点请求被执行多次,例如 GET /A、GET /B、 GET /A。
为了等待所有请求完成并保证页面已完全加载,赛普拉斯的最佳实践是什么。
我不想使用很多cy.wait()命令来等待所有请求被处理。(每个页面有很多不同的请求组)
我正在用PHP构建API.其中一种方法是place.new(PUT请求).它需要几个字符串字段,它还需要一个图像.但是我无法让它发挥作用.使用POST请求很简单,但我不知道如何使用PUT以及如何在服务器上获取数据.
谢谢您的帮助!
$curl = curl_init();
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($curl, CURLOPT_URL, $this->url);
curl_setopt($curl, CURLOPT_PUT, 1);
curl_setopt($curl, CURLOPT_INFILE, $image);
curl_setopt($curl, CURLOPT_INFILESIZE, filesize($image));
$this->result = curl_exec($curl);
curl_close($curl);
Run Code Online (Sandbox Code Playgroud)
if ( $im_s = file_get_contents('php://input') )
{
$image = imagecreatefromstring($im_s);
if ( $image != '' )
{
$filename = sha1($title.rand(11111, 99999)).'.jpg';
$photo_url = $temp_dir . $filename;
imagejpeg($image, $photo_url);
// upload image
...
}
}
Run Code Online (Sandbox Code Playgroud)
// Correct: /Users/john/Sites/....
// Incorrect: http://localhost/...
$image = fopen($file_on_dir_not_url, …Run Code Online (Sandbox Code Playgroud) 在我的助手模块中,我有:
def abc(url)
...
if request.env['HTTP_USER_AGENT']
do something
end
end
Run Code Online (Sandbox Code Playgroud)
在我的spec文件中,我有:
describe "#abc" do
before(:each) do
@meth = :abc
helper.request.env['HTTP_USER_AGENT'] = "..."
end
it "should return the webstart jnlp file" do
@obj.send(@meth, "some_url").should ....
end
end
Run Code Online (Sandbox Code Playgroud)
当我运行规范时,我有这个错误:
undefined local variable or method `request' for <ObjectWithDocHelperMixedIn:0x00000103b5a7d0>
Run Code Online (Sandbox Code Playgroud)
如何在我的规范中存根request.env ['...']?
谢谢.
我想转换传入的http响应,它是一个流并将数据存储在一个变量中.我对节点流并不多,我正在努力做到这一点.
request('http://google.com/doodle.png', function (error, response, body) {
image = new Buffer(body, 'binary');
db.images.insert({ filename: 'google.png', imgData: image}, function (err) {
// handle errors etc.
});
})
Run Code Online (Sandbox Code Playgroud)
UPDATE
这是我的完整代码.我的目标是通过请求获取图像并将其存储在mongodb中.但是图像总是被破坏了.我认为因为请求响应是一个流,图像只是部分保存,因此腐败.
request('http://google.com/doodle.png', function (error, response, body) {
image = new Buffer(body, 'binary');
db.images.insert({ filename: 'google.png', imgData: image}, function (err) {
// handle errors etc.
});
})
Run Code Online (Sandbox Code Playgroud)
既然你已经澄清了请求缓冲区的响应,那就是我如何正确保存图像而不会损坏.