如何从角度$ http发布请求获取json字符串 [英] how to get json string from angular $http post request
问题描述
我正在发送此POST,我想先查看请求中发送的字符串,然后再发送它.
I am sending this POST, I want to see the string that get's sent in the request before I send it.
这是柱塞
$http.post('/someUrl', {msg:'hello word!'}).
then(function(response) {
// this callback will be called asynchronously
// when the response is available
}, function(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
我想我想做的是看到JSON字符串被发送到服务器.
I guess what I am trying to do is see the JSON string being sent to the server.
推荐答案
如果您使用这样的config选项访问
if you are hitting the url with config option like this
var config = {
headers: { 'Content-type': 'application/json' },
'dataType': 'json'
};
var data = {
name: 'intekhab',
age:26,
};
$http.post('/admin/header', data, config).then(function(response){
console.log(response);
});
然后您可以查看发送的数据.打开浏览器console
并单击network
,然后在network
click
下的URL中输入
现在看一下Request Payload under header tab
在那里,您的数据将显示您已发送到服务器的内容.
Then you can see the data what are send. Open your browser console
and click network
then under network
click
your url what you have hit
And now see the look at Request Payload under header tab
There your data will be revealing what you have send to server.
如果您不使用这样的配置选项
And if you are not using config option like this
var data = {
name: 'intekhab',
age:26,
};
$http.post('/admin/header', data).then(function(response){
console.log(response);
});
然后执行与上述相同的操作,唯一的区别是您在Request Payload
下看到了数据,现在您将在Form Data
Then do the same as above only difference is where you have seen the data under Request Payload
, now you will see the same data under Form Data
这篇关于如何从角度$ http发布请求获取json字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!