所以目前我想发送一个post请求到我的API使用puppeteer。这是我的代码
await page.setRequestInterception(true);
//resultFromCrawl.map(value => {
//const cac = JSON.stringify(resultFromCrawl[0])
page.on('request', interceptedRequest => {
// Here, is where you change the request method and
// add your post data
var data = {
'method': 'POST',
'postData': queryString.stringify(JSON.stringify(resultFromCrawl[0])),
'headers': {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
}
};
interceptedRequest.continue(data);
});
const response = await page.goto(`http:my-url-post/post`)
const responseBody = await response.text();
所以我得到一个错误在jackson解析器作为响应从服务器
JSON parse error: Unexpected character ('=' (code 61)): Expected space separating root-level values; nested exception is com.fasterxml.jackson.core.JsonParseException
我的对象是(resultfromrawl [0])
{
alias: 'some-thing-some-thing',
title: 'Some thing some thing',
date: '15:21 | 23/01/2021',
publicationTime: 1611386441332,
excerpt: 'some thing some thing',
status: 'PUBLISHED',
url: 'some url',
composingType: 'Tự viết',
type: 'Bài',
penName: 'Nam',
featuredImage: 'someImage',
websiteId: 'websiteId',
authorId: 'authorId',
categoryId: 'cateId',
isFeatured: false,
seo: {
metaDescription: '',
metaImage: '',
metaSameArticle: true,
metaTitle: '',
ogDescription: '',
ogImage: '',
ogSameArticle: true,
ogTitle: ''
},
postContent: '<html>Html stuff here</html>'
}
有什么想法吗?还是我解析错了什么?感谢阅读
我真笨。只需删除postData中的queryString:"postData":JSON.stringify (resultFromCrawl [0])我们可以开始了