Skip to content

Commit c7bdd58

Browse files
committed
adding test case for default content type
1 parent 86a3e2b commit c7bdd58

20 files changed

Lines changed: 311 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
"net/http"
7+
"io/ioutil"
8+
)
9+
10+
func main() {
11+
12+
url := "http://mockbin.com/har"
13+
14+
payload := strings.NewReader("Hello World")
15+
16+
req, _ := http.NewRequest("POST", url, payload)
17+
18+
req.Header.Add("content-type", "text/plain")
19+
20+
res, _ := http.DefaultClient.Do(req)
21+
22+
defer res.Body.Close()
23+
body, _ := ioutil.ReadAll(res.Body)
24+
25+
fmt.Println(res)
26+
fmt.Println(string(body))
27+
28+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
HttpResponse<String> response = Unirest.post("http://mockbin.com/har")
2+
.header("content-type", "text/plain")
3+
.body("Hello World")
4+
.asString();
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var settings = {
2+
"async": true,
3+
"crossDomain": true,
4+
"url": "http://mockbin.com/har",
5+
"method": "POST",
6+
"headers": {
7+
"content-type": "text/plain"
8+
},
9+
"data": "Hello World"
10+
}
11+
12+
$.ajax(settings).done(function (response) {
13+
console.log(response);
14+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
var data = "Hello World";
2+
3+
var xhr = new XMLHttpRequest();
4+
xhr.withCredentials = true;
5+
6+
xhr.addEventListener("readystatechange", function () {
7+
if (this.readyState === this.DONE) {
8+
console.log(this.responseText);
9+
}
10+
});
11+
12+
xhr.open("POST", "http://mockbin.com/har");
13+
xhr.setRequestHeader("content-type", "text/plain");
14+
15+
xhr.send(data);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
var http = require("http");
2+
3+
var options = {
4+
"method": "POST",
5+
"hostname": "mockbin.com",
6+
"port": null,
7+
"path": "/har",
8+
"headers": {
9+
"content-type": "text/plain"
10+
}
11+
};
12+
13+
var req = http.request(options, function (res) {
14+
var chunks = [];
15+
16+
res.on("data", function (chunk) {
17+
chunks.push(chunk);
18+
});
19+
20+
res.on("end", function () {
21+
var body = Buffer.concat(chunks);
22+
console.log(body.toString());
23+
});
24+
});
25+
26+
req.write("Hello World");
27+
req.end();
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
var request = require("request");
2+
3+
request({
4+
"method": "POST",
5+
"url": "http://mockbin.com/har",
6+
"headers": {
7+
"content-type": "text/plain"
8+
},
9+
"body": "Hello World"
10+
}, function (error, response, body) {
11+
if (error) throw new Error(error);
12+
13+
console.log(body);
14+
});
15+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
var unirest = require("unirest");
2+
3+
var req = unirest("POST", "http://mockbin.com/har");
4+
5+
req.headers({
6+
"content-type": "text/plain"
7+
});
8+
9+
req.send("Hello World");
10+
11+
req.end(function (res) {
12+
if (res.error) throw new Error(res.error);
13+
14+
console.log(res.body);
15+
});
16+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#import <Foundation/Foundation.h>
2+
3+
NSDictionary *headers = @{ @"content-type": @"text/plain" };
4+
5+
NSData *postData = [[NSData alloc] initWithData:[@"Hello World" dataUsingEncoding:NSUTF8StringEncoding]];
6+
7+
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://mockbin.com/har"]
8+
cachePolicy:NSURLRequestUseProtocolCachePolicy
9+
timeoutInterval:10.0];
10+
[request setHTTPMethod:@"POST"];
11+
[request setAllHTTPHeaderFields:headers];
12+
[request setHTTPBody:postData];
13+
14+
NSURLSession *session = [NSURLSession sharedSession];
15+
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
16+
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
17+
if (error) {
18+
NSLog(@"%@", error);
19+
} else {
20+
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
21+
NSLog(@"%@", httpResponse);
22+
}
23+
}];
24+
[dataTask resume];
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
open Cohttp_lwt_unix
2+
open Cohttp
3+
open Lwt
4+
5+
let uri = Uri.of_string "http://mockbin.com/har" in
6+
let headers = Header.init ()
7+
|> fun h -> Header.add h "content-type" "text/plain"
8+
in
9+
let body = Cohttp_lwt_body.of_string "Hello World" in
10+
11+
Client.call ~headers ~body `POST uri
12+
>>= fun (res, body_stream) ->
13+
(* Do stuff with the result *)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
$curl = curl_init();
4+
5+
curl_setopt_array($curl, array(
6+
CURLOPT_URL => "http://mockbin.com/har",
7+
CURLOPT_RETURNTRANSFER => true,
8+
CURLOPT_ENCODING => "",
9+
CURLOPT_MAXREDIRS => 10,
10+
CURLOPT_TIMEOUT => 30,
11+
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
12+
CURLOPT_CUSTOMREQUEST => "POST",
13+
CURLOPT_POSTFIELDS => "Hello World",
14+
CURLOPT_HTTPHEADER => array(
15+
"content-type: text/plain"
16+
),
17+
));
18+
19+
$response = curl_exec($curl);
20+
$err = curl_error($curl);
21+
22+
curl_close($curl);
23+
24+
if ($err) {
25+
echo "cURL Error #:" . $err;
26+
} else {
27+
echo $response;
28+
}

0 commit comments

Comments
 (0)