小编and*_*dko的帖子

WebApi 2.1 PUT抛出错误415

我正在尝试使用WebApi PUT方法更新数据.我的代码之前工作正常,但突然间我开始得到这个错误.

"Message":"The request contains an entity body but no Content-Type header. The inferred media type 'application/octet-stream' is not supported for this resource.","ExceptionMessage":"No MediaTypeFormatter is available to read an object of type 'xEmployee' from content with media type 'application/octet-stream'.","ExceptionType":"System.Net.Http.UnsupportedMediaTypeException".
Run Code Online (Sandbox Code Playgroud)

这是标题:响应标题.

HTTP/1.1 415 Unsupported Media Type
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/7.5
Set-Cookie: Role=D65520F37D105E39C1A92C15CD482E378F32A769592AC7D8305285A5B9B90362F7F2F13F14E6DC220E44D26940B06B52E7460EF13184F245805AF9523D1072464F4BD06AFB4F8AEB8B7D8BF607A8922C6041A3A4C636BF3B26388E606A94FE43; expires=Tue, 07-Oct-2014 09:49:56 GMT; path=/
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Tue, 07 Oct 2014 09:19:56 GMT
Content-Length: 809
Run Code Online (Sandbox Code Playgroud)

请求标题:

PUT /api/xemployees/2110481232 HTTP/1.1 …
Run Code Online (Sandbox Code Playgroud)

asp.net-web-api http-status-code-415

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

有什么理由在 TypeScript 中使用静态/私有静态方法?

我正在考虑但找不到在 TypeScript 类中使用静态方法(尤其是私有静态)的任何理由。我在胡思乱想什么吗?我问这个问题是因为我看到了这样的代码:

class Abc {

  public someMethod() {
     Abc.myMethod();
  }

  private static myMethod() {
     ...
  }
} 
Run Code Online (Sandbox Code Playgroud)

PS对于那些试图向我解释静态和非静态方法之间的区别以及什么是私有方法的人。由于我多年的 C# 背景,我非常了解这些。如果您仔细阅读问题 - 这是关于在 TypeScript 中使用这些。

oop typescript

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

Jwt令牌授权不起作用

我正在尝试创建Jwt令牌授权.为此目的,我有发行者部分代码,如:

public override Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
    context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] {"*"});
    Users user;
    using (var db = new UserStore())
    {
        user = Task.Run(()=> db.FindUser(context.UserName, context.Password, context.ClientId)).Result;
    }
    if (user == null)
    {
        context.SetError("invalid_grant", "The user name or password is incorrect");
        return Task.FromResult<object>(null);
    }
    var identity = new ClaimsIdentity("JWT");
    identity.AddClaim(new Claim(ClaimTypes.Name, user.Email));
    identity.AddClaim(new Claim("sub", context.UserName));
    identity.AddClaim(new Claim(ClaimTypes.Role, user.Roles.Name));

    var props = new AuthenticationProperties(new Dictionary<string, string>
    {
        {
            "audience", context.ClientId ?? string.Empty
        }
    });
    var ticket = new AuthenticationTicket(identity, props);
    context.Validated(ticket);
    return Task.FromResult<object>(null); …
Run Code Online (Sandbox Code Playgroud)

c# authorization oauth-2.0 jwt owin

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

Jest 无法解析文件 - 无法在模块外部使用 import 语句

我想将 Jest 与 TypeScript 和 React 一起使用,但测试套件因以下错误而失败:

\n
Jest encountered an unexpected token\n\n    Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.\n\n    Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.\n\n    By default "node_modules" folder is ignored by transformers.\n\n    Here's what you can do:\n     \xe2\x80\xa2 If …
Run Code Online (Sandbox Code Playgroud)

typescript jestjs babeljs ts-jest

9
推荐指数
0
解决办法
2996
查看次数

尝试通过 Dropbox Javascript SDK 访问 Dropbox API 时出现错误 400

我有一个通过 Dropbox Javascript SDK 尝试下载文件的应用程序。我不知道出了什么问题。通过 fetch 调用访问 Dropbox API 会直接带来相同的错误。Dropbox API 文档说错误 400 是错误的输入参数,而看起来我发送的内容没有问题 - "Dropbox-API-Arg":"{\"path\":\"/1/price.xlsx\" }"

const Dropbox = require("dropbox").Dropbox;
import axios from "axios";
import fs = require("fs");
import { logger } from "./logger";

export class FileHandler {
    public async handle(path: string, token: string): Promise<void> {
        try {
            const dbx = new Dropbox({ fetch: axios, accessToken: token });
            dbx.filesDownload({ path })
                .then((data) => {
                    fs.writeFile(data.name, data.fileBinary, "binary", (err) => {
                        if (err) { throw err; }
                    });
                })
                .catch((error: …
Run Code Online (Sandbox Code Playgroud)

javascript node.js dropbox-api

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

由于Crosswalk,构建离子应用程序失败

突然,我开始得到这个错误:

C:\Users\andrey.shedko\Documents\Visual Studio 2015\Projects\BBN.Mobile\BBN.Mobile>ionic run android
Running command: "C:\Program Files\nodejs\node.exe" "C:\Users\andrey.shedko\Documents\Visual Studio 2015\Projects\BBN.Mobile\BBN.Mobile\hooks\after_prepare\010_add_platform_class.js" "C:\Users\andrey.shedko\Documents\Visual Studio 2015\Projects\BBN.Mobile\BBN.Mobile"
add to body class: platform-android
ANDROID_HOME=D:\Android\SDK
JAVA_HOME=C:\Program Files\java\jdk1.8.0_73
No target specified, deploying to emulator
No emulator specified, defaulting to BBN
Waiting for emulator...
Hax is enabled
Hax ram_size 0x30000000
HAX is working and emulator runs in fast virt mode.
console on port 5554, ADB on port 5555
Booting up emulator (this may take a while)......BOOT COMPLETE
null
org.xwalk:xwalk_core_library_beta:18+

FAILURE: Build failed with an exception. …
Run Code Online (Sandbox Code Playgroud)

android ionic-framework crosswalk

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

服务器发送事件未使用React和NodeJ从流接收消息

我有一个非常简单的设置。
节点

export default class StreamController {
    public static newMessage = async (req: Request, res: Response) => {
        const { userid } = req.params;
        res.writeHead(200, {
            "Connection": "keep-alive",
            "Content-Type": "text/event-stream",
            "Cache-Control": "no-cache",
        });
        setInterval(async () => {
            console.log(await MessagesController.hasNewMessage(userid));
            res.write(`${JSON.stringify({ hasUnread: await MessagesController.hasNewMessage(userid) })}`);
            res.write("\n\n");
        }, 5000);
    }
}
Run Code Online (Sandbox Code Playgroud)

反应

 constructor() {
        super();
        const uid = getUserId();
        const eventSource = new EventSource(`http://localhost:8080/stream/messages/${uid}`)

        eventSource.onmessage = (e) => {
            console.log(e)
        }
    }
Run Code Online (Sandbox Code Playgroud)

我可以看到该流已打开,但是没有任何事件从服务器传递,而在服务器端发布了数据。我做错了什么?

node.js server-sent-events reactjs

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

Promise.all().finally() 可以返回未解析的数据吗?

我发现 Promise.all().finally() 的行为非常不寻常 - 看起来它在应用 map() 之前返回数据。
1.从数据库接收数据。
2. 在map() 内调用Google Maps API,应用于从数据库检索的数据,并使用Google API 调用的结果添加到对象属性“Distance”。
3. 在 Promise.all() 中返回数据 - 收到的数据没有新属性。我不明白这怎么可能?

public static get = async (req: Request, res: Response) => {
    const latitude = req.query.lat;
    const longitude = req.query.long;
    const pool = await new sql.ConnectionPool(CommonConstants.connectionString).connect();
    const request = pool.request();
    const result = await request.execute('SuppliersSP');
    sql.close();
    const rows = result.recordset.map(async (supplier) => {
        const data = { origin: [latitude, longitude], destination: [supplier.Latitude, supplier.Longitude] };
        const distance = await GetDistance(data) || …
Run Code Online (Sandbox Code Playgroud)

node.js async-await es6-promise

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

Knockout.js按钮点击更新ViewModel

好吧,那不是最好的情况说明......无论如何,我正在尝试更新我的ViewModel,但它无法正常工作.默认情况下,我从控制器功能和按钮单击 - 从同一个控制器中的另一个函数获取数据,但ViewModel仅包含在第一次ViewModel初始化后收到的数据.

<script>
     function viewModel () {
        var self = this;
        self.currentPage = ko.observable();
        self.pageSize = ko.observable(10);
        self.currentPageIndex = ko.observable(0);
        self.salesdata = ko.observableArray();
        self.newdata = ko.observable();
        self.currentPage = ko.computed(function () {
            var pagesize = parseInt(self.pageSize(), 10),
            startIndex = pagesize * self.currentPageIndex(),
            endIndex = startIndex + pagesize;
            return self.salesdata.slice(startIndex, endIndex);
        });
        self.nextPage = function () {
            if (((self.currentPageIndex() + 1) * self.pageSize()) < self.salesdata().length) {
                self.currentPageIndex(self.currentPageIndex() + 1);
            }
            else {
                self.currentPageIndex(0);
            }
        }
        self.previousPage = function () {
            if …
Run Code Online (Sandbox Code Playgroud)

javascript jquery mvvm knockout.js

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

如何将纯Angular应用作为项目添加到Visual Studio解决方案?

我想将带有纯JavaScript / Less / Node文件的Angular应用程序添加到Visual Studio解决方案作为UI层,但是却没有创建基本的默认基础结构,而VS甚至对空项目也是如此。怎么做?

visual-studio angularjs

4
推荐指数
2
解决办法
4819
查看次数