curl istekde
curl POST 'localhost/send'
ahmet
123
şeklinde istek göndermek istiyorum, konfigirasyonu nasıl tasarlamalıyım.
Nodejs hakkında soru
6
●172
- 12-12-2022, 14:26:11Selam
php için
$url = "localhost/send"; $headers = [ 'Content-Type: application/json; Cache-Control: no-cache' ]; $POST = [ 'param1' => $value1, 'param2' => $value2]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($POST)); $response = curl_exec($ch);node.js için xhr kütüphanesini çağırın
var XMLHttpRequest = require('xhr2'); var xhr = new XMLHttpRequest(); var url = "localhost/send"; xhr.open("POST", url, true); xhr.setRequestHeader("Content-Type", "application/json", "Cache-Control", "no-cache"); var datab = JSON.stringify({ "ad": 'ahmet', "soyad": 'mehmet' }); - 12-12-2022, 14:27:36Hocam aslında sorum,webkaplani adlı üyeden alıntı: mesajı görüntüle
Nodejs express konfigirasyonu içindi
içerisinde nasıl bir config tasarlayıp.
bu şekilde istek gönderilecek hale getirmeliyim şeklinde - 12-12-2022, 14:35:22Fronttan gelen postu backend içerisinde yakalayıp body-parser ile ayırıyorsunuz. Gönderilen istekler standart değerlere sahip ise basit bir kalıp yazabilirsiniz.adwerd0z1 adlı üyeden alıntı: mesajı görüntüle
var express = require('express'); var bodyParser = require('body-parser'); var app = express(); app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.json()) var port = 9000; app.post('datacek/test', function(req, res) { console.log('Data alındı.'); console.log('Data: ',req.body); res.send(req.body); }); app.listen(port); console.log('Dinleme başlatıldı [url]http://localhost:[/url]' + port);Böyle birşeyde yapabilirsin
https://stackoverflow.com/questions/...r-post-request - 12-12-2022, 14:51:07hallettim teşekkürlerwebkaplani adlı üyeden alıntı: mesajı görüntüle