标签: httpresponse

下载字节数组文件

我有已转换的文件并将其插入到我的数据库中:

byte[] file = File.ReadAllBytes(outputpath);
string filesting = Convert.ToBase64String(file);
//INSERT INTO DB
Run Code Online (Sandbox Code Playgroud)

然后我从数据库中提取它并尝试下载它。

byte[] bytes = Convert.FromBase64String(file);
HttpContext.Current.Response.ContentType = "application/force-download";
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=labtest.avi");
HttpContext.Current.Response.BinaryWrite(bytes);
HttpContext.Current.Response.End();
Run Code Online (Sandbox Code Playgroud)

但没有下载任何内容。

为什么?

c# asp.net httpresponse

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

symfony 从 url 下载视频

我正在尝试使用 symfony 从外部 URL 下载视频。所以我有这条路线,如果我直接在浏览器中点击它,我会收到两个可能的答案:视频已播放或(如果浏览器无法重现),视频是从这个外部 URL 下载的。我试图创建的是来自控制器的响应,以始终下载视频。我已经尝试了几种解决方案,但都没有运气。

一些尝试的解决方案:

$response = new BinaryFileResponse($url);
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT);

return $response;
Run Code Online (Sandbox Code Playgroud)

由于它不是静态文件,因此失败。

也试过

$response = new RedirectResponse($url);
$response->headers->set('Content-Type', 'video');
$d = $response->headers->makeDisposition(
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
$videoUrl
);
$response->headers->set('Content-Disposition', $d);
Run Code Online (Sandbox Code Playgroud)

当然,“StreamedResponse”……我假设这是可能的,因为当浏览器中的格式没有正确转换时,我会得到所需的行为……感谢任何帮助。

php response httpresponse symfony

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

在未处理的请求上发送哪个 HTTP 响应代码

我有一个 PHP 应用程序,它有一个路由器,它应该有两个默认处理程序401 Unauthorized404 Not Found

但也有可能没有为这两种情况设置处理程序。在这种情况下,我需要有一个默认响应,告诉Request Unhandled我已将其设置为响应代码400 Bad Request,但我觉得它不是真正合适的。

对于未处理的请求,我应该使用什么响应代码?

php http httpresponse httprequest

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

why html tags are not working inside servlet?

I'm new to Servlets I just trying to print a simple Html tag inside servlet response but I dunno why it doesn't print in Browser. it just print the String without getting the Html tags.

Here is the code:

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("Hi All");
        PrintWriter out =response.getWriter();
        out.println("<h2>Please complete our Customer Survey</h2>");

    }

}
Run Code Online (Sandbox Code Playgroud)

**Out Put print as **

<h2>Please complete our Customer Survey</h2>
Run Code Online (Sandbox Code Playgroud)

Please let me know how to fix this Thanks.

html java servlets httpresponse

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

无法访问 HttpResponseMessage 的正文

我目前正在使用 .NET Core Web App 开发 API 以进行测试,但我一直坚持这个。

实际上,我有这个代码:

namespace CoreWebApp.API.Admin
{
    [Route("api/country")]
    public class CountryController : Controller
    {
        // GET: api/country
        [HttpGet]
        public HttpResponseMessage Get()
        {
            List<Country> countries = Shared.Database.SqlAction.CountriesTable.GetCountries();
            return new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(JsonConvert.SerializeObject(countries), Encoding.UTF8, "application/json") };
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我想要做的是返回一个HttpStatusCode和一个HttpContent。然后我应该在 Postman 上得到它:

[
    {
        "Name":"France"
    },
    {
        "Name":"Germany"
    },
    {
        "Name":"Spain"
    },
    ....
]
Run Code Online (Sandbox Code Playgroud)

状态代码 OK 200


但是,我根本没有得到这个身体,我得到的是:

{
    "version": {
        "major": 1,
        "minor": 1,
        "build": -1,
        "revision": -1,
        "majorRevision": …
Run Code Online (Sandbox Code Playgroud)

c# httpresponse httpcontent asp.net-core-mvc asp.net-core

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

响应头 Content-Disposition 没有做任何事情

我正在尝试从我的服务器(使用 ASP.NET Core MVC)检索文件并将其显示在浏览器中。在浏览了此处和其他站点上的许多线程后,似乎每次都建议相同的解决方案;这是在响应标头中使用内联的 Content-Disposition。我的代码如下:

IFileInfo file = _fileProvider.GetFileInfo(filename);
Response.Headers.Add("Content-Disposition", $"inline; {file.Name}");
return File(file.CreateReadStream(), "application/pdf", file.Name);
Run Code Online (Sandbox Code Playgroud)

虽然这似乎是基于我见过的其他线程的正确代码,但 Content-Disposition 标头在我的代码中绝对没有任何作用。无论我有标题、删除它还是制作其他东西(即附件),它都会下载并保存文件,但除非我手动打开文件,否则不会显示它。

有谁知道我在这里想念什么?

httpresponse content-disposition response-headers asp.net-core-mvc .net-core

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

JsonResponse 中的 Django HttpResponse

在我的 django 项目中,为了避免另一个请求,我想返回一个带有 HttpResponse 的 JsonResponse,如下所示:

JsonResponse({"known": True, "space": render(request, 'space.html')}, status=200)

Django进程返回正常的内部错误Object of type HttpResponse is not JSON serializable

我尝试了所有的网络解决方案(序列化器等),但找不到一种方法来返回带有字典条目的 json 格式(我的 javascript 必需的),其中一个是我可以与 then 一起使用的整个 html 页面$("body").html(response["space"])

我错过了什么吗?

谢谢你的时间。

python django serialization httpresponse jsonresponse

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

在烧瓶中重定向后返回自定义 http 代码

在那里我是烧瓶的新手。场景:我试图在提交表单后重定向到某个路由。所以我为此使用了烧瓶重定向以及代码参数。

@topics_bp.route('/create_topic/',methods =['GET','POST'] )
def create_topic():
    if request.method == 'GET':
        #send the form for create topic!
        formData = TopicForm()
        return render_template('create-topic.html',form = formData)
    if request.method == 'POST':
        # check the post method and redirect
        
        return redirect(url_for('topic.topics'),code=201)
Run Code Online (Sandbox Code Playgroud)

基本上,我想为创建的记录返回 HTTP 代码 201,然后重定向到预期的路由。但是如果我这样做,它只会返回一个重定向页面。每次我都需要手动点击。 重定向页面

是否有任何解决方法可以返回 201 代码并自动重定向?提前致谢!

python http httpresponse flask

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

Invoke-WebRequest 一个返回 json 字符串的 API 返回整数列表?

在 Chrome DevTools 的网络选项卡中,我右键单击请求并选择“Copy => Copy as PowerShell”并获得以下脚本。请求的“响应”是一个 json 字符串。

$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession
 $session.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36"
 $session.Cookies.Add((New-Object System.Net.Cookie("INGRESSCOOKIE", "1661198715.885.38.892935", "/", "xx.com")))
 $response = Invoke-WebRequest -UseBasicParsing -Uri "https://xx.com/api/v1/xxx?filter[reportDate]=2022-08-24&filter[forceReload]=true" `
 -WebSession $session `
 -Headers @{
 "method"="GET"
   "authority"="xx.com"
   "scheme"="https"
   "path"="/api/v1/sum? Filter[reportDate]=2022-08-24&filter[forceReload]=true"
   "sec-ch-ua"="`"Chromium`";v=`"94`", `"Google Chrome`";v=`"94`", `";Not A Brand`";v=`"99`""
   "accept"="application/vnd.api+json"
   "authorization"="Bearer $($token. Token)"
   "sec-ch-ua-mobile"="?0"
   "sec-ch-ua-platform"="`"Windows`""
   "origin"="https://xx.com"
   "sec-fetch-site"="same-site"
   "sec-fetch-mode"="cors"
   "sec-fetch-dest"="empty"
   "referrer"="https://xx.com/"
   "accept-encoding"="gzip, deflate, br"
   "accept-language"="en-US,en;q=0.9"
 } `
 -ContentType "application/vnd.api+json"
Run Code Online (Sandbox Code Playgroud)

但是,Write-Output $response.Content得到的是整数列表而不是 json …

powershell http httpresponse

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

Google App Engine 上的 Laravel 应用因响应大于 450KB 而挂起

我在 Google App Engine (GAE)Standard ENV 上托管的 Laravel 应用程序面临着一个令人困惑的问题。虽然应用程序在本地环境中完美运行,但在 GAE 上托管时我遇到了一个特定问题:大于约 450KB 的 API 响应永远不会完成;请求挂起,我没有收到任何错误,也没有触发任何日志。

语境

  • 本地环境:应用程序运行没有问题。我可以接收任何大小的 JSON 响应,包括几 MB 的有效负载。
  • Google App Engine 环境:响应大于 450KB 的请求挂起。GAE 中没有指示该问题的错误日志。
  • 响应类型:JSON 响应和 HTML Blade 页面呈现都会出现此问题。
  • GAE 实例大小:我已尝试将实例资源扩展到最大,但问题仍然存在。
  • 进行的测试:我已经对不同大小的响应进行了测试来隔离问题,但它似乎与超过 450KB 的响应有特定的联系。

我已经检查过的内容

  1. App Engine 配置:我没有发现任何可以限制响应大小的特定设置。
  2. 有效负载限制:我知道 GAE 上的有效负载限制远高于 450KB。
  3. 超时和资源:响应处理时间从未超过一秒,因此似乎不是超时或资源不足的问题。
  4. 日志记录:GAE 日志中没有指示问题原因的错误或警告。

具体问题

  1. GAE 中是否存在可能导致此行为的隐藏设置或限制?
  2. 这是否是与处理特定于 GAE 标准环境的大型响应相关的问题?
  3. 我还可以采取哪些其他故障排除步骤来进一步查明原因?

任何有关类似问题的建议或经验都会非常有帮助。

php google-app-engine httpresponse laravel

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