Json 正文中的Http Post字符串值

Json 正文中的Http Post字符串值,json,ajax,angular,http,post,Json,Ajax,Angular,Http,Post,Http头的内容类型是application/x-www-form-urlencoded 我必须发布一个字符串值。 environmentId:“predevnet” 在我的上一个项目中,我使用JQuery进行ajax调用: $.ajax({ headers: this.headers, type: this.type, url: this.url, data: {environmentId: "predevnet"},

Http头的内容类型是
application/x-www-form-urlencoded

我必须发布一个字符串值。
environmentId:“predevnet”

在我的上一个项目中,我使用JQuery进行ajax调用:

    $.ajax({
        headers: this.headers,
        type: this.type,
        url: this.url,
        data: {environmentId: "predevnet"},
        dataType: this.dataType,
        contentType: this.contentType,
        async: isAsync,
        success: success,
        cache: this.cache,
        error: error
    });
现在我也在试着打同样的电话

return this.http
    .post(this.baseUrl + action, JSON.stringify({environmentId: "predevnet"}), options)
    .map(response => response.json() as DcResponse<T>);`
返回this.http
.post(this.baseUrl+action,JSON.stringify({environmentId:“predevnet”}),选项)
.map(response=>response.json()作为DcResponse)`
预期结果:表单数据应如下所示:

return this.http
    .post(this.baseUrl + action, '=predevnet', options)
    .map(response => response.json() as DcResponse<T>);`

stringify是这样的:

当您只想在POST请求主体中发送一个键值对作为参数时,您必须省略键部分

return this.http
    .post(this.baseUrl + action, '=predevnet', options)
    .map(response => response.json() as DcResponse<T>);`
因此,如果您希望内容类型为
application/x-www-form-urlencoded
,那么您的示例必须如下所示:

return this.http
    .post(this.baseUrl + action, '=predevnet', options)
    .map(response => response.json() as DcResponse<T>);`

如果只想在POST请求主体中发送一个键值对作为参数,则必须省略键部分

因此,如果您希望内容类型为
application/x-www-form-urlencoded
,那么您的示例必须如下所示:

return this.http
    .post(this.baseUrl + action, '=predevnet', options)
    .map(response => response.json() as DcResponse<T>);`

如果将Content-Type头设置为application/json,是否有效?没有,我尝试过,但它发送了一个json对象。。它必须只发送名称为的变量。您是否尝试使用
toString()
而不是
JSON.stringify()
?如果将内容类型头设置为application/JSON,是否有效?不,我尝试过,但它发送了一个JSON对象。。它必须只发送带有名称的变量。您是否尝试使用
toString()
而不是
JSON.stringify()