Are you first timer at Why not join us and start exchange your programming knowledge with everyone. Register today!

Next JS -fetch API with POST method

0 votes
added Mar 1 in Next JS by LC Marshal Captain (20,750 points)
import React from 'react';
import PropTypes from 'prop-types';
import fetch from 'isomorphic-unfetch';
import { URLSearchParams } from 'url';
import Layout from '../components/template/Layout';

global.URLSearchParams = URLSearchParams;

const Test = () => (
  <Layout classProp="frontpage">
    {/* <FrontMainComponent data={JSONdata} /> */}

Test.getInitialProps = async () => {
  const formData = new URLSearchParams();
  formData.append('property_id', 1000168);
  formData.append('type', 'm');
  formData.append('field_prop_listing_type', 'sale');
  const res = await fetch('', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    body: formData,

  const data = await res.json();

export default Test;


Please log in or register to response this reference. - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.