• 12-12-2022, 14:24:28
    #1
    curl istekde

    curl POST 'localhost/send'
    ahmet
    123

    şeklinde istek göndermek istiyorum, konfigirasyonu nasıl tasarlamalıyım.
  • 12-12-2022, 14:26:11
    #2
    Selam
    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:36
    #3
    webkaplani adlı üyeden alıntı: mesajı görüntüle
    Selam

            $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);
    Hocam aslında sorum,
    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:30:15
    #4
    Regnos.com
    Axios kullanabilirsin nodejs icin. Npm de ornek sorgular vardir
  • 12-12-2022, 14:33:03
    #5
    Nodejs Axios kullanabilirsiniz hocam. Direk curl paketi istiyorsanız bunu kullanabilirsiniz.
  • 12-12-2022, 14:35:22
    #6
    adwerd0z1 adlı üyeden alıntı: mesajı görüntüle
    Hocam aslında sorum,
    Nodejs express konfigirasyonu içindi
    içerisinde nasıl bir config tasarlayıp.

    bu şekilde istek gönderilecek hale getirmeliyim şeklinde
    Fronttan 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.

    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:07
    #7
    webkaplani adlı üyeden alıntı: mesajı görüntüle
    Fronttan 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.

    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
    hallettim teşekkürler