Loading POST requests

BrowserWindow can load local or remote content using POST requests. You can do a form post and load the response into the BrowserWindow in the Electron. The loadURL method also provides you the option to override the user agent while requesting the resource: 

const { BrowserWindow, app } = require('electron');
let appShell = null;

function createMainWindow() {
let win = new BrowserWindow({ width: 600, height: 400 });
let url = require('url').format({
protocol: 'http',
slashes: true,
pathname: "localhost:8080/post"
});
win.loadURL(url, {
postData: [
{
type: 'rowData',
bytes: Buffer.from('param1=value&param2=value')
}
],
extraHeaders: 'Content-Type: application/x-www-form-urlencoded',
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36'
});
return win;
}

app.on('ready', () => { mainWindow = createMainWindow(); });

Instead of passing the URL as a string, here we use Node.js URL module to compose the URL string, which is better always with the Electron. Here, the window is loaded from the local server but the URL that we provided is accepted as only a POST request. So, we need to pass the second argument to the loadURL method with the parameter values inside the postData. As I mentioned, you can override the user agent string using the userAgent property. The loadURL method can also be used to upload a file or blob data. The type can be rowData, file, filesystem, or blob depending upon the type of the post method. Use file if you want to loadURL that accepts the file to be uploaded on request.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.154.86