【问题标题】:Angular JS http Request to .NET ServerAngular JS http请求到.NET服务器
【发布时间】:2018-02-15 11:41:54
【问题描述】:

我正在尝试使用 Angular JS 向 .NET 服务器发出 post 请求

我能够得到响应,但服务器没有看到我的请求数据。

客户:

var header = {"Content-Type":"multipart/form-data"};

var data = {name:"bill", email:"bill@email.com", phone:"1234567890" };

$http.post("//dot.net/resource", data, header).then(function(res){

    console.log(res.data);

},function(err){ console.log(err); });

服务器:

if(HttpContext.Current.Request.HttpMethod.ToString().ToLower() == "post") {

    Response.Write("hello request");      // I see this in the response
    Response.Write(Request.Form["name"]); // nothing : (
}

我对@9​​87654324@ 不是很熟悉。 Request.Form 基本上像 php 中的 $_POST 吗?

如何使用$http 将一些变量传递给服务器?

【问题讨论】:

    标签: javascript .net angularjs ajax curl


    【解决方案1】:

    尝试使用JSON.stringify(data) 将数据作为字符串发送。此外,您可以明确指定内容类型标头 'Content-Type': 'application/json'

    【讨论】:

      猜你喜欢
      • 2014-10-07
      • 1970-01-01
      • 2017-03-07
      • 2022-11-09
      • 2015-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-31
      相关资源
      最近更新 更多