我正在测试看看我对网站的POST请求是否有效,但是没有输出任何内容。当我使用RunKit时,它将显示输出,但不在我的Powershell中。我是在做错什么还是没有输出?如何使它显示输出?这是我的代码:
var request = require('request');
request.post(
'My_API_URL',
{ json: { "text":"this is my text" } },
function (error, response, body) {
console.log(body);
}
);
答案 0 :(得分:0)
我建议您这样做的是更新代码,然后重试:
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.2.1/css/bootstrap.min.css" rel="stylesheet">
<main class='container'>
<section class='row'>
<form lass="form-inline col-sm-12">
<fieldset class="form-group">
<label class="input-group-text input-group col-sm-6" for="inputGroupSelect02">Rows</label>
<select id="inputGroupSelect02" class="custom-select col-sm-6">
<option selected value=''>Choose how many rows you need</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
<option value="4">Four</option>
<option value="5">Five</option>
<option value="6">Six</option>
</select>
</fieldset>
<fieldset class="form-group">
<label class="input-group-text input-group col-sm-6" for="inputGroupSelect03">Columns</label>
<select id="inputGroupSelect03" class="custom-select col-sm-6">
<option selected value=''>Choose how many columns you need</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
<option value="4">Four</option>
<option value="5">Five</option>
<option value="6">Six</option>
</select>
</fieldset>
<button id="button" class="btn btn-success float-right" type="button" disabled>Insert</button>
</form>
</section>
<hr>
<section class='row'>
<figure class='table-responsive'>
<table class='table table-hover'>
<tbody></tbody>
</table>
</figure>
</section>
</main>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
让我知道结果是否相同。
答案 1 :(得分:0)
选中此link。您应该这样发布请求:
var request = require('request');
var body = JSON.stringify({
client_id: '0123456789abcdef',
client_secret: 'secret',
code: 'abcdef'
});
request.post({
url: 'https://postman-echo.com/post',
body: body,
headers: {
'Content-Type': 'application/json'
}},
function (error, response, body) {
console.log(body);
}
);