标签: response

在C#中调用Response.End()后重定向到另一个页面

我正在将webview导出为ex​​cel,在Web应用程序中使用.Net 4.0,页面加载,需要生成文件,然后将页面重定向到调用页面.我遇到了问题,因为我导出到excel的代码如下:

gvSummary.Style.Add("font-size", ".6em");
    Response.Clear();
    string attachment = "attachment; filename=filename.xls";
    Response.ClearContent();
    Response.AddHeader("content-disposition", attachment);
    Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
    StringWriter sw = new StringWriter();
    HtmlTextWriter htw = new HtmlTextWriter(sw);
    gvSummary.GridLines = GridLines.Horizontal;
    gvSummary.RenderControl(htw);
    Response.Write(sw.ToString());
    Response.End();
Run Code Online (Sandbox Code Playgroud)

我知道如果我在.End()之前放置Response.Redirect(),我将被重定向但是文件永远不会生成,如果我在.End()之后放置Response.Redirect()我得到文件但没有重定向.

上面编写的代码在生成文件时效果很好,但是在生成文件之后,我仍然看不到我的加载动画,因为我无法突破页面.有任何想法吗?

c# gridview response.redirect web-applications response

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

Angular2 - HTTP 200被视为错误

我想让Angular2与我的Asp.Net WebApi 2服务器一起工作.我设法正确处理了一些GET请求,但是这个POST请求表现得很奇怪.我从服务器收到OK(200)响应,但以下代码将其视为错误:

public Register(){
    this.accountService.Register(this.Name, this.Password, this.RepeatPassword, this.Email, this.Skype, this.Website).subscribe(
        () => {      //this is what's supposed to be called, but isn't
            this.accountService.Login(this.Name, this.Password).subscribe(
                res => {
                    console.log(res);
                    localStorage.setItem('token', res);
                    localStorage.setItem('user', this.Name);
                    this.router.navigate(['Home']);
                },
                error2 => {
                    console.log(error2.Message);
                }
            );
        },
        error => { //the response gets here, instead of being handled above
            console.log(error.Message);
        }
    );
}
Run Code Online (Sandbox Code Playgroud)

这是accountService的Register方法:

public Register (userName:string, password:string, confirmPassword:string, email:string, skype:string, website:string)
{
    return this.http.post(this.Uri + 'api/Account/Register', JSON.stringify(
        {
            UserName: userName,
            Password: password,
            ConfirmPassword: confirmPassword, …
Run Code Online (Sandbox Code Playgroud)

ajax http response angularjs asp.net-web-api2

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

生成一个空白响应对象用于测试

有没有办法生成具有所有属性的空白响应对象,或者我必须自己创建该类?

我只想为烧瓶应用程序提供一些比这样做更干净的东西:

    class fake_request():
        status_code = None
        text = None
    response = fake_request()
Run Code Online (Sandbox Code Playgroud)

python response flask

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

nodeJS 防止 res.download 超时

我对 nodeJS 服务器进行了 POST 调用,该服务器在 mongo 数据库上搜索一些数据并返回包含所请求数据的 CSV 文件。问题是数据搜索和处理超过了nodeJS默认的2分钟超时。

在不同的场景中 y 使用:

res.writeHeader(200,'application/json');            
res.write('starting fetch .... ');
Run Code Online (Sandbox Code Playgroud)

res.write('');通过不时发送一些请求来保持请求的活动状态并防止客户端超时。

现在我用来res.download()下载生成的 csv 文件,因此不仅仅是发送 JSON 作为响应。

尝试像这样使用这个解决方案:

res.writeHeader(200,'application/json');            
res.write('starting fetch .... ');
res.download()
Run Code Online (Sandbox Code Playgroud)

但我收到“标头已发送”错误。

关于如何防止数据处理和文件下载完成之前超时的想法吗?

提前致谢

timeout response download node.js express

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

如何解码编码的 HttpWebResponse?

我有这段代码可以从 URL 获取页面 HTML,但是响应内容看起来是经过编码的。

代码:

    HttpWebRequest xhr = (HttpWebRequest) WebRequest.Create(new Uri("https://www.youtube.com/watch?v=_Ewh75YGIGQ"));
        xhr.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
        //xhr.CookieContainer = request.Account.CookieContainer;
        xhr.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
        xhr.Headers["Accept-Encoding"] = "gzip, deflate, br";
        xhr.Headers["Accept-Language"] = "en-US,en;q=0.5";
        xhr.Headers["Upgrade-Insecure-Requests"] = "1";
        xhr.KeepAlive = true;
        xhr.UserAgent = "Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 6.1)";
        xhr.Host = "www.youtube.com";
        xhr.Referer = "https://www.youtube.com/watch?v=6aCpYxzRkf4";
        var response = xhr.GetResponse();
        string html;
        using (StreamReader reader = new StreamReader(response.GetResponseStream()))
        {
            html = reader.ReadToEnd();
        }
Run Code Online (Sandbox Code Playgroud)

这些是响应标头:

    X-XSS-Protection: 1; mode=block; report=https://www.google.com/appserve/security-bugs/log/youtube
    X-Content-Type-Options: nosniff
    X-Frame-Options: SAMEORIGIN
    Strict-Transport-Security: max-age=31536000
    Content-Encoding: …
Run Code Online (Sandbox Code Playgroud)

html c# response decoding

5
推荐指数
2
解决办法
6967
查看次数

如何在 GraphQL 中返回 json 字符串作为响应

我是一个相当新的 graphQL。我的要求是发送查询时,graphQL 应返回 JSON 响应,如下所示

{
    user: '$',
    name: 'Josh',
    age: '30'
}
Run Code Online (Sandbox Code Playgroud)

我尝试了以下方法,但没有达到结果。

var express = require('express');
var graphqlHTTP = require('express-graphql');
var { buildSchema } = require('graphql');

var schema = buildSchema(`
  type Query {
    user: String!
  }
`);


// JSON
var json = {
    user: '$',
    name: 'Josh',
    age: '30'
};

var root = {
    user: () => {
      return json;
    }
};

var app = express();
app.use('/graphql', graphqlHTTP({
  schema: schema,
  rootValue: root,
  graphiql: true,
}));
app.listen(4000);
console.log('Running a …
Run Code Online (Sandbox Code Playgroud)

json response graphql

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

如何在使用 Typegoose 获取数据的同时使用类转换器序列化 Nest js 响应?

我一直在尝试使用 Typegoose 使用类转换器库来完成 Mongodb 序列化部分的 NestJs 示例。https://docs.nestjs.com/techniques/serialization中给出的示例仅展示了如何在 TypeORM 中使用序列化。我对 Typegoose 遵循了相同的流程。这是我到目前为止所尝试过的。

// cat.domain.ts

import { prop } from '@typegoose/typegoose';

export class Cat {
  @prop()
  name: string;

  @prop()
  age: number;

  @prop()
  breed: string;
}


// cats.service.ts

@Injectable()
export class CatsService {
  constructor(
    @InjectModel(Cat) private readonly catModel: ReturnModelType<typeof Cat>,
  ) {}

  findAll(): Observable<Cat[]> {
    return from(this.catModel.find().exec());
  }

  findOne(id: string): Observable<Cat> {
    return from(this.catModel.findById(id).exec());
  }
  ...
}

// cat.response.ts

import { ObjectId } from 'mongodb';
import { Exclude, Transform } from …
Run Code Online (Sandbox Code Playgroud)

serialization response nestjs class-transformer typegoose

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

如何在 springdoc Schema 中描述标准 Spring 错误响应?

如果出现未处理的错误,SpringBoot 应用程序的默认服务器响应是

{
    "timestamp": 1594232435849,
    "path": "/my/path",
    "status": 500,
    "error": "Internal Server Error",
    "message": "this request is failed because of ...",
    "requestId": "ba5058f3-4"
}
Run Code Online (Sandbox Code Playgroud)

我想在应用程序路由的 Springdoc 注释中描述它。

假设有一个标准类DefaultErrorResponse(只是一个模拟名称),它可能如下所示:

@Operation(
  // ... other details
  responses = {
    // ... other possible responses
    @ApiResponse(
      responseCode = "500",
      content = @Content(schema = @Schema(implementation = DefaultErrorResponse.class)))
  }
)
Run Code Online (Sandbox Code Playgroud)

在更糟糕的情况下,这样的类不存在,Spring 仅使用Map底层来创建响应。那么这个注释将更加详细,包括明确提及响应中包含的每个字段。

显然,对于大多数路线来说,这部分@ApiResponse(responseCode="500",...是相同的,并且最好减少重复。

在文档中引入默认错误响应描述的正确方法是什么?

spring response spring-boot springdoc

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

如何模拟获取响应对象

我尝试使用 ts-jest 模拟获取响应,但遇到打字稿错误

import { mocked } from 'ts-jest/utils';
import fetch from 'node-fetch';

import { getInstallationAccessToken } from './index';

const mockedFetch = mocked(fetch, true);

describe('getInstallationAccessToken', () => {
  const TODAY = new Date();
  const TOMORROW = new Date();
  TOMORROW.setDate(TODAY.getDate() + 1);

  beforeEach(() => {
    mockedFetch.mockResolvedValue({
      status: 200,
      json: async () => ({
        token: 'MOCKED_GITHUB_INSTALLATION_ACCESS_TOKEN',
        expires_at: TOMORROW.toISOString()
      })
    });
    jest.clearAllMocks();
  });

  test('generates github app jwt token', async () => {
    await getInstallationAccessToken();
    expect(mockedJwt.sign).toBeCalledTimes(1);
  });
})
Run Code Online (Sandbox Code Playgroud)

在此示例中,我收到以下错误:

Argument of type '{ status: …
Run Code Online (Sandbox Code Playgroud)

response fetch typescript jestjs ts-jest

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

何时使用 ResponseStatusException 和 ControllerAdvice

Spring 5 引入了 ResponseStatusException,这让我陷入了困境,不知道在什么情况下可以使用 ResponseStatusException 和 ControllerAdvice,因为它们非常相似。

谁能帮我这个?

error-handling exception response httpresponse controller-advice

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