Skip to main content
var url = "http://10.1.1.1:30080/apigateway/apinizerlog/InsertLog";
var tarih = new Date().toISOString();
var servisAdi = 'Servis Adı Yazılacak';
var uygulama = 'Uygulama Adı Yazılacak';
var ip = headerMap.get('X-Forwarded-For');
var kullaniciAdi = headerMap.get('username');
var parametre = JSON.stringify(bodyText);
var data = JSON.stringify({
  "Tarih": tarih,
  "ServisAdi": servisAdi,
  "IP": ip,
  "KullaniciAdi": kullaniciAdi,
  "Parametre": parametre,
  "Uygulama": uygulama
});
try {
  var con = new java.net.URL(url).openConnection();
  con.setConnectTimeout(15000);
  con.setReadTimeout(15000);
  con.setRequestMethod("PUT");
  con.setUseCaches(false);
  con.setDoInput(true);
  con.setDoOutput(true);
  con.setRequestProperty("Content-Length", data.length);
  var wr = new java.io.DataOutputStream(con.getOutputStream());
  wr.writeBytes(data);
  wr.flush();
  wr.close();
  con.getResponseCode(); // önemli silinmemesi gerekli
} catch (err) {
}

Example Explanation

This example sends JSON data with PUT method to an endpoint defined within Apinizer. It retrieves IP address and username information from request headers, converts body content to JSON format, and sends it to the specified endpoint.
The con.getResponseCode() call is necessary for the connection to complete and should not be deleted.