Skip to content

Commit

Permalink
Examples for different scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
anytizer committed Sep 10, 2019
1 parent 642a753 commit efc89a7
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 0 deletions.
20 changes: 20 additions & 0 deletions examples/cs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://hookb.in/xxxxxxxxxxxxxx");

httpWebRequest.ContentType = "application/json";
httpWebRequest.Method = "POST";

using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
string json = "{\"name\":\"John\"}";

streamWriter.Write(json);
streamWriter.Flush();
streamWriter.Close();
}

var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
}
1 change: 1 addition & 0 deletions examples/curl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl -X POST -H "Content-Type: application/json" -d '{"name": "John"}' https://hookb.in/xxxxxxxxxxxxxx
14 changes: 14 additions & 0 deletions examples/go.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
jsonStr := []byte(`{"name": "John"}`)

req, err := http.NewRequest("POST", "https://hookb.in/xxxxxxxxxxxxxx", bytes.NewBuffer(jsonStr))
req.Header.Set("Content-Type", "application/json")

client := &http.Client{}

resp, err := client.Do(req)

if err != nil {
panic(err)
}

defer resp.Body.Close()
12 changes: 12 additions & 0 deletions examples/jquery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
$.ajax({
type: "POST",
url: "https://hookb.in/xxxxxxxxxxxxxx",
data: JSON.stringify({
"name": "John"
}),
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (data) {
console.log("done.");
}
});
23 changes: 23 additions & 0 deletions examples/node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const https = require("https");

const data = JSON.stringify({
name: "John"
})

const options = {
hostname: "hookb.in",
port: 443,
path: "/xxxxxxxxxxxxxx",
method: "POST",
headers: {
"Content-Type": "application/json",
"Content-Length": data.length
}
}

const req = https.request(options, (res) => {
console.log(`status: ${res.statusCode}`);
});

req.write(data);
req.end();
9 changes: 9 additions & 0 deletions examples/pearl.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
my $uri = 'https://hookb.in/xxxxxxxxxxxxxx';
my $req = HTTP::Request->new('POST', $uri);
my $data = '{"name": "John"}';

$req->header('Content-Type' => 'application/json');
$req->content($data);

my $lwp = LWP::UserAgent->new;
$lwp->request($req);
14 changes: 14 additions & 0 deletions examples/php.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
$handle = curl_init('https://hookb.in/xxxxxxxxxxxxxx');

$data = [
'name' => 'John'
];

$encodedData = json_encode($data);

curl_setopt($handle, CURLOPT_POST, 1);
curl_setopt($handle, CURLOPT_POSTFIELDS, $encodedData);
curl_setopt($handle, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);

$result = curl_exec($handle);
9 changes: 9 additions & 0 deletions examples/python.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import requests

url = 'https://hookb.in/xxxxxxxxxxxxxx'

data = {
"name": "John"
}

r = requests.post(url, verify=False, json=data)
1 change: 1 addition & 0 deletions examples/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Examples copied from hook bin.
11 changes: 11 additions & 0 deletions examples/ruby.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
uri = URI('https://hookb.in/xxxxxxxxxxxxxx')

req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')

req.body = {
name: 'John'
}.to_json

res = Net::HTTP.start(uri.hostname, uri.port) do |http|
http.request(req)
end
17 changes: 17 additions & 0 deletions examples/vanila.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var xhr = new XMLHttpRequest();

xhr.open("POST", "https://hookb.in/xxxxxxxxxxxxxx", true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");

xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
console.log("done.");
}
};

var data = JSON.stringify({
"name": "John"
});

xhr.send(data);

0 comments on commit efc89a7

Please sign in to comment.