parse headers more like curl and query more like python (#362)

* parse headers more like curl and query like python

* --data sets content-type

* update sample in readme

* actually handle empty -H
This commit is contained in:
Boris Verkhovskiy
2022-03-26 01:44:46 -07:00
committed by GitHub
parent a532bd4158
commit 6a43531ec4
138 changed files with 581 additions and 155 deletions

View File

@@ -3,10 +3,12 @@
`curlconverter` transpiles [`curl`](https://en.wikipedia.org/wiki/CURL) commands into programs in other programming languages.
```sh
$ curlconverter --data "Hello, world!" example.com
$ curlconverter --data-raw "hello=world" example.com
import requests
data = 'Hello, world!'
data = {
'hello': 'world',
}
response = requests.post('http://example.com', data=data)
```

View File

@@ -3,4 +3,6 @@
uri:
url: 'http://localhost:28139'
method: POST
headers:
Content-Type: 'application/x-www-form-urlencoded'
register: result

View File

@@ -6,4 +6,6 @@
body:
123
body_format: json
headers:
Content-Type: 'application/x-www-form-urlencoded'
register: result

View File

@@ -6,4 +6,6 @@
body:
"msg1=wow&msg2=such&msg3=@rawmsg"
body_format: json
headers:
Content-Type: 'application/x-www-form-urlencoded'
register: result

View File

@@ -6,4 +6,6 @@
body:
{"keywords":"php","page":1,"searchMode":1}
body_format: json
headers:
Content-Type: 'application/x-www-form-urlencoded'
register: result

View File

@@ -6,6 +6,8 @@
body:
{"admins":{"names":[],"roles":[]},"readers":{"names":["joe"],"roles":[]}}
body_format: json
headers:
Content-Type: 'application/x-www-form-urlencoded'
url_username: admin
url_password: 123
register: result

View File

@@ -1 +1 @@
curl --header "Content-Type: text/xml;charset=UTF-8" --header "getWorkOrderCancel" postman-echo.com/get
curl --header "Content-Type: text/xml;charset=UTF-8" --header "getWorkOrderCancel;" postman-echo.com/get

View File

@@ -1,10 +1,14 @@
import 'package:http/http.dart' as http;
void main() async {
var headers = {
'Content-Type': 'application/x-www-form-urlencoded',
};
var data = 'foo=\"bar\"';
var url = Uri.parse('http://example.com/');
var res = await http.post(url, body: data);
var res = await http.post(url, headers: headers, body: data);
if (res.statusCode != 200) throw Exception('http.post error: statusCode= ${res.statusCode}');
print(res.body);
}

View File

@@ -1,10 +1,14 @@
import 'package:http/http.dart' as http;
void main() async {
var headers = {
'Content-Type': 'application/x-www-form-urlencoded',
};
var data = 'foo=\'bar\'';
var url = Uri.parse('http://example.com/');
var res = await http.post(url, body: data);
var res = await http.post(url, headers: headers, body: data);
if (res.statusCode != 200) throw Exception('http.post error: statusCode= ${res.statusCode}');
print(res.body);
}

View File

@@ -1,10 +1,14 @@
import 'package:http/http.dart' as http;
void main() async {
var headers = {
'Content-Type': 'application/x-www-form-urlencoded',
};
var data = 'msg1=wow&msg2=such&msg3=@rawmsg';
var url = Uri.parse('http://example.com/post');
var res = await http.post(url, body: data);
var res = await http.post(url, headers: headers, body: data);
if (res.statusCode != 200) throw Exception('http.post error: statusCode= ${res.statusCode}');
print(res.body);
}

View File

@@ -1,10 +1,14 @@
import 'package:http/http.dart' as http;
void main() async {
var headers = {
'Content-Type': 'application/x-www-form-urlencoded',
};
var data = 'foo="bar"';
var url = Uri.parse('http://example.com/');
var res = await http.post(url, body: data);
var res = await http.post(url, headers: headers, body: data);
if (res.statusCode != 200) throw Exception('http.post error: statusCode= ${res.statusCode}');
print(res.body);
}

View File

@@ -1,10 +1,14 @@
import 'package:http/http.dart' as http;
void main() async {
var headers = {
'Content-Type': 'application/x-www-form-urlencoded',
};
var data = 'foo="bar"';
var url = Uri.parse('http://example.com/');
var res = await http.post(url, body: data);
var res = await http.post(url, headers: headers, body: data);
if (res.statusCode != 200) throw Exception('http.post error: statusCode= ${res.statusCode}');
print(res.body);
}

View File

@@ -1,10 +1,14 @@
import 'package:http/http.dart' as http;
void main() async {
var headers = {
'Content-Type': 'application/x-www-form-urlencoded',
};
var data = 'foo=\'bar\'';
var url = Uri.parse('http://example.com/');
var res = await http.post(url, body: data);
var res = await http.post(url, headers: headers, body: data);
if (res.statusCode != 200) throw Exception('http.post error: statusCode= ${res.statusCode}');
print(res.body);
}

View File

@@ -7,8 +7,8 @@ void main() async {
var authn = 'Basic ' + base64Encode(utf8.encode('$uname:$pword'));
var headers = {
'Authorization': authn,
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': authn,
};
var data = '{"admins":{"names":[], "roles":[]}, "readers":{"names":["joe"],"roles":[]}}';

View File

@@ -2,7 +2,9 @@ request = %HTTPoison.Request{
method: :post,
url: "https://cmdb.litop.local/webservices/rest.php",
options: [],
headers: [],
headers: [
{~s|Content-Type|, ~s|application/x-www-form-urlencoded|},
],
params: [],
body: [
{~s|version|, ~s|1.2|},

View File

@@ -2,7 +2,9 @@ request = %HTTPoison.Request{
method: :post,
url: "http://localhost/api/oauth/token/",
options: [hackney: [basic_auth: {~s|foo|, ~s|bar|}]],
headers: [],
headers: [
{~s|Content-Type|, ~s|application/x-www-form-urlencoded|},
],
params: [],
body: [
{~s|grant_type|, ~s|client_credentials|}

View File

@@ -2,7 +2,9 @@ request = %HTTPoison.Request{
method: :post,
url: "http://localhost:28139",
options: [],
headers: [],
headers: [
{~s|Content-Type|, ~s|application/x-www-form-urlencoded|},
],
params: [],
body: ""
}

View File

@@ -2,7 +2,9 @@ request = %HTTPoison.Request{
method: :post,
url: "http://example.com/",
options: [],
headers: [],
headers: [
{~s|Content-Type|, ~s|application/x-www-form-urlencoded|},
],
params: [],
body: [
{~s|foo|, ~s|\\"bar\\"|}

View File

@@ -2,7 +2,9 @@ request = %HTTPoison.Request{
method: :post,
url: "http://example.com/",
options: [],
headers: [],
headers: [
{~s|Content-Type|, ~s|application/x-www-form-urlencoded|},
],
params: [],
body: [
{~s|foo|, ~s|\\\'bar\\\'|}

View File

@@ -2,7 +2,9 @@ request = %HTTPoison.Request{
method: :post,
url: "http://a.com",
options: [],
headers: [],
headers: [
{~s|Content-Type|, ~s|application/x-www-form-urlencoded|},
],
params: [],
body: ~s|123|
}

View File

@@ -2,7 +2,9 @@ request = %HTTPoison.Request{
method: :post,
url: "http://google.com",
options: [],
headers: [],
headers: [
{~s|Content-Type|, ~s|application/x-www-form-urlencoded|},
],
params: [],
body: [
{~s|field|, ~s|don\'t you like quotes|}

View File

@@ -2,7 +2,9 @@ request = %HTTPoison.Request{
method: :post,
url: "http://example.com/",
options: [],
headers: [],
headers: [
{~s|Content-Type|, ~s|application/x-www-form-urlencoded|},
],
params: [],
body: [
{~s|foo|, ~s|bar|},

View File

@@ -2,7 +2,9 @@ request = %HTTPoison.Request{
method: :post,
url: "http://localhost:28139/post",
options: [],
headers: [],
headers: [
{~s|Content-Type|, ~s|application/x-www-form-urlencoded|},
],
params: [],
body: ~s|{"title":"china1"}|
}

View File

@@ -2,7 +2,9 @@ request = %HTTPoison.Request{
method: :post,
url: "http://example.com/post",
options: [],
headers: [],
headers: [
{~s|Content-Type|, ~s|application/x-www-form-urlencoded|},
],
params: [],
body: [
{~s|msg1|, ~s|wow|},

View File

@@ -2,7 +2,9 @@ request = %HTTPoison.Request{
method: :post,
url: "http://example.com/",
options: [],
headers: [],
headers: [
{~s|Content-Type|, ~s|application/x-www-form-urlencoded|},
],
params: [],
body: [
{~s|foo|, ~s|"bar"|}

View File

@@ -2,7 +2,9 @@ request = %HTTPoison.Request{
method: :post,
url: "http://example.com/",
options: [],
headers: [],
headers: [
{~s|Content-Type|, ~s|application/x-www-form-urlencoded|},
],
params: [],
body: [
{~s|foo|, ~s|"bar"|}

View File

@@ -2,7 +2,9 @@ request = %HTTPoison.Request{
method: :post,
url: "http://example.com/",
options: [],
headers: [],
headers: [
{~s|Content-Type|, ~s|application/x-www-form-urlencoded|},
],
params: [],
body: [
{~s|foo|, ~s|\'bar\'|}

View File

@@ -2,7 +2,9 @@ request = %HTTPoison.Request{
method: :post,
url: "http://us.jooble.org/api/xxxxxxxxxxxxxxxx",
options: [],
headers: [],
headers: [
{~s|Content-Type|, ~s|application/x-www-form-urlencoded|},
],
params: [],
body: ~s|{"keywords":"php","page":1,"searchMode":1}|
}

View File

@@ -2,7 +2,9 @@ request = %HTTPoison.Request{
method: :put,
url: "http://localhost:5984/test/_security",
options: [hackney: [basic_auth: {~s|admin|, ~s|123|}]],
headers: [],
headers: [
{~s|Content-Type|, ~s|application/x-www-form-urlencoded|},
],
params: [],
body: ~s|{"admins":{"names":[], "roles":[]}, "readers":{"names":["joe"],"roles":[]}}|
}

View File

@@ -2,7 +2,9 @@ request = %HTTPoison.Request{
method: :put,
url: "http://awesomeurl.com/upload",
options: [],
headers: [],
headers: [
{~s|Content-Type|, ~s|application/x-www-form-urlencoded|},
],
params: [],
body: {:file, ~s|new_file|}
}

View File

@@ -13,6 +13,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
resp, err := client.Do(req)
if err != nil {
log.Fatal(err)

View File

@@ -15,6 +15,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
resp, err := client.Do(req)
if err != nil {
log.Fatal(err)

View File

@@ -12,6 +12,8 @@ class Main {
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestMethod("PATCH");
httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
httpConn.setDoOutput(true);
OutputStreamWriter writer = new OutputStreamWriter(httpConn.getOutputStream());
writer.write("item[]=1&item[]=2&item[]=3");

View File

@@ -12,6 +12,8 @@ class Main {
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestMethod("POST");
httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
httpConn.setDoOutput(true);
OutputStreamWriter writer = new OutputStreamWriter(httpConn.getOutputStream());
writer.write("data1=data1&data2=data2&data3=data3");

View File

@@ -13,6 +13,7 @@ class Main {
httpConn.setRequestMethod("GET");
httpConn.setRequestProperty("Origin", "http://fiddle.jshell.net");
httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
httpConn.setDoOutput(true);
OutputStreamWriter writer = new OutputStreamWriter(httpConn.getOutputStream());

View File

@@ -12,6 +12,8 @@ class Main {
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestMethod("POST");
httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
httpConn.setDoOutput(true);
OutputStreamWriter writer = new OutputStreamWriter(httpConn.getOutputStream());
writer.write("version=1.2&auth_user=fdgxf&auth_pwd=oxfdscds&json_data={ \"operation\": \"core/get\", \"class\": \"Software\", \"key\": \"key\" }");

View File

@@ -13,6 +13,8 @@ class Main {
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestMethod("POST");
httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
byte[] message = ("foo:bar").getBytes("UTF-8");
String basicAuth = DatatypeConverter.printBase64Binary(message);
httpConn.setRequestProperty("Authorization", "Basic " + basicAuth);

View File

@@ -11,6 +11,8 @@ class Main {
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestMethod("POST");
httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
InputStream responseStream = httpConn.getResponseCode() / 100 == 2
? httpConn.getInputStream()
: httpConn.getErrorStream();

View File

@@ -12,6 +12,8 @@ class Main {
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestMethod("POST");
httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
httpConn.setDoOutput(true);
OutputStreamWriter writer = new OutputStreamWriter(httpConn.getOutputStream());
writer.write("foo=\\\"bar\\\"");

View File

@@ -12,6 +12,8 @@ class Main {
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestMethod("POST");
httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
httpConn.setDoOutput(true);
OutputStreamWriter writer = new OutputStreamWriter(httpConn.getOutputStream());
writer.write("foo=\\'bar\\'");

View File

@@ -12,6 +12,8 @@ class Main {
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestMethod("POST");
httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
httpConn.setDoOutput(true);
OutputStreamWriter writer = new OutputStreamWriter(httpConn.getOutputStream());
writer.write("123");

View File

@@ -12,6 +12,8 @@ class Main {
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestMethod("POST");
httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
httpConn.setDoOutput(true);
OutputStreamWriter writer = new OutputStreamWriter(httpConn.getOutputStream());
writer.write("field=don%27t%20you%20like%20quotes");

View File

@@ -12,6 +12,8 @@ class Main {
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestMethod("POST");
httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
httpConn.setDoOutput(true);
OutputStreamWriter writer = new OutputStreamWriter(httpConn.getOutputStream());
writer.write("foo=bar&foo=&foo=barbar");

View File

@@ -12,6 +12,8 @@ class Main {
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestMethod("POST");
httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
httpConn.setDoOutput(true);
OutputStreamWriter writer = new OutputStreamWriter(httpConn.getOutputStream());
writer.write("{\"title\":\"china1\"}");

View File

@@ -12,6 +12,8 @@ class Main {
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestMethod("POST");
httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
httpConn.setDoOutput(true);
OutputStreamWriter writer = new OutputStreamWriter(httpConn.getOutputStream());
writer.write("msg1=wow&msg2=such&msg3=@rawmsg");

View File

@@ -12,6 +12,8 @@ class Main {
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestMethod("POST");
httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
httpConn.setDoOutput(true);
OutputStreamWriter writer = new OutputStreamWriter(httpConn.getOutputStream());
writer.write("secret=*%5*!");

View File

@@ -12,6 +12,8 @@ class Main {
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestMethod("POST");
httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
httpConn.setDoOutput(true);
OutputStreamWriter writer = new OutputStreamWriter(httpConn.getOutputStream());
writer.write("foo=\"bar\"");

View File

@@ -12,6 +12,8 @@ class Main {
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestMethod("POST");
httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
httpConn.setDoOutput(true);
OutputStreamWriter writer = new OutputStreamWriter(httpConn.getOutputStream());
writer.write("foo=\"bar\"");

View File

@@ -16,6 +16,7 @@ class Main {
httpConn.setRequestProperty("A", "''a'");
httpConn.setRequestProperty("B", "\"");
httpConn.setRequestProperty("Cookie", "x=1'; y=2\"");
httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
byte[] message = ("ol':asd\"").getBytes("UTF-8");
String basicAuth = DatatypeConverter.printBase64Binary(message);

View File

@@ -12,6 +12,8 @@ class Main {
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestMethod("POST");
httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
httpConn.setDoOutput(true);
OutputStreamWriter writer = new OutputStreamWriter(httpConn.getOutputStream());
writer.write("foo='bar'");

View File

@@ -12,6 +12,8 @@ class Main {
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestMethod("POST");
httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
httpConn.setDoOutput(true);
OutputStreamWriter writer = new OutputStreamWriter(httpConn.getOutputStream());
writer.write("{\"keywords\":\"php\",\"page\":1,\"searchMode\":1}");

View File

@@ -13,6 +13,8 @@ class Main {
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestMethod("PUT");
httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
byte[] message = ("admin:123").getBytes("UTF-8");
String basicAuth = DatatypeConverter.printBase64Binary(message);
httpConn.setRequestProperty("Authorization", "Basic " + basicAuth);

View File

@@ -1,3 +1,6 @@
fetch('http://localhost:28139', {
method: 'POST'
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
});

View File

@@ -1,4 +1,7 @@
fetch('http://example.com/', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: 'foo=\"bar\"'
});

View File

@@ -1,4 +1,7 @@
fetch('http://example.com/', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: 'foo=\\\'bar\\\''
});

View File

@@ -1,7 +1,7 @@
fetch('http://localhost:28139/post', {
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=UTF-8'
'Content-Type': 'application/x-www-form-urlencoded'
},
body: JSON.stringify({"title":"china1"})
});

View File

@@ -1,4 +1,7 @@
fetch('http://example.com/post', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: 'msg1=wow&msg2=such&msg3=@rawmsg'
});

View File

@@ -1,4 +1,7 @@
fetch('http://example.com/', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: 'foo="bar"'
});

View File

@@ -1,4 +1,7 @@
fetch('http://example.com/', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: 'foo="bar"'
});

View File

@@ -1,4 +1,7 @@
fetch('http://example.com/', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: 'foo=\'bar\''
});

View File

@@ -1,7 +1,7 @@
fetch('http://localhost:5984/test/_security', {
method: 'PUT',
headers: {
'Content-Type': 'application/json; charset=UTF-8',
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Basic ' + btoa('admin:123')
},
body: JSON.stringify({"admins":{"names":[], "roles":[]}, "readers":{"names":["joe"],"roles":[]}})

View File

@@ -2,6 +2,9 @@
"url": "http://httpbin.org/post",
"raw_url": "http://httpbin.org/post",
"method": "post",
"headers": {
"Content-Type": "application/x-www-form-urlencoded"
},
"data": {
"data1": "data1",
"data2": "data2",

View File

@@ -2,6 +2,9 @@
"url": "http://httpbin.org/patch",
"raw_url": "http://httpbin.org/patch",
"method": "patch",
"headers": {
"Content-Type": "application/x-www-form-urlencoded"
},
"data": {
"item[]": [
"1",

View File

@@ -2,6 +2,9 @@
"url": "http://httpbin.org/post",
"raw_url": "http://httpbin.org/post",
"method": "post",
"headers": {
"Content-Type": "application/x-www-form-urlencoded"
},
"data": {
"data1": "data1",
"data2": "data2",

View File

@@ -2,6 +2,9 @@
"url": "https://cmdb.litop.local/webservices/rest.php",
"raw_url": "https://cmdb.litop.local/webservices/rest.php",
"method": "post",
"headers": {
"Content-Type": "application/x-www-form-urlencoded"
},
"data": {
"version": "1.2",
"auth_user": "fdgxf",

View File

@@ -2,6 +2,9 @@
"url": "http://localhost:28139/post",
"raw_url": "http://localhost:28139/post",
"method": "post",
"headers": {
"Content-Type": "application/x-www-form-urlencoded"
},
"data": {
"{\"title\":\"china1\"}": ""
}

View File

@@ -2,6 +2,9 @@
"url": "http://example.com/post",
"raw_url": "http://example.com/post",
"method": "post",
"headers": {
"Content-Type": "application/x-www-form-urlencoded"
},
"data": {
"msg1": "wow",
"msg2": "such",

View File

@@ -2,6 +2,9 @@
"url": "http://us.jooble.org/api/xxxxxxxxxxxxxxxx",
"raw_url": "http://us.jooble.org/api/xxxxxxxxxxxxxxxx",
"method": "post",
"headers": {
"Content-Type": "application/x-www-form-urlencoded"
},
"data": {
"{\"keywords\":\"php\",\"page\":1,\"searchMode\":1}": ""
}

View File

@@ -1,13 +1,15 @@
%% Web Access using Data Import and Export API
uri = 'https://cmdb.litop.local/webservices/rest.php';
body = 'version=1.2&auth_user=fdgxf&auth_pwd=oxfdscds&json_data={ "operation": "core/get", "class": "Software", "key": "key" }';
response = webwrite(uri, body);
options = weboptions('MediaType', 'application/x-www-form-urlencoded');
response = webwrite(uri, body, options);
%% HTTP Interface
import matlab.net.*
import matlab.net.http.*
import matlab.net.http.io.*
header = HeaderField('Content-Type', 'application/x-www-form-urlencoded');
uri = URI('https://cmdb.litop.local/webservices/rest.php');
body = FormProvider(...
'version', '1.2',...
@@ -19,4 +21,4 @@ body = FormProvider(...
'key', 'key'...
))...
);
response = RequestMessage('post', [], body).send(uri.EncodedURI);
response = RequestMessage('post', header, body).send(uri.EncodedURI);

View File

@@ -3,7 +3,8 @@ uri = 'http://localhost/api/oauth/token/';
body = 'grant_type=client_credentials';
options = weboptions(...
'Username', 'foo',...
'Password', 'bar'...
'Password', 'bar',...
'MediaType', 'application/x-www-form-urlencoded'...
);
response = webwrite(uri, body, options);
@@ -12,8 +13,9 @@ import matlab.net.*
import matlab.net.http.*
import matlab.net.http.io.*
header = HeaderField('Content-Type', 'application/x-www-form-urlencoded');
uri = URI('http://localhost/api/oauth/token/');
cred = Credentials('Username', 'foo', 'Password', 'bar');
options = HTTPOptions('Credentials', cred);
body = FormProvider('grant_type', 'client_credentials');
response = RequestMessage('post', [], body).send(uri.EncodedURI, options);
response = RequestMessage('post', header, body).send(uri.EncodedURI, options);

View File

@@ -1,13 +1,15 @@
%% Web Access using Data Import and Export API
uri = 'http://localhost:28139';
body = '';
response = webwrite(uri, body);
options = weboptions('MediaType', 'application/x-www-form-urlencoded');
response = webwrite(uri, body, options);
%% HTTP Interface
import matlab.net.*
import matlab.net.http.*
import matlab.net.http.io.*
header = HeaderField('Content-Type', 'application/x-www-form-urlencoded');
uri = URI('http://localhost:28139');
body = FileProvider();
response = RequestMessage('post', [], body).send(uri.EncodedURI);
response = RequestMessage('post', header, body).send(uri.EncodedURI);

View File

@@ -1,13 +1,15 @@
%% Web Access using Data Import and Export API
uri = 'http://a.com';
body = '123';
response = webwrite(uri, body);
options = weboptions('MediaType', 'application/x-www-form-urlencoded');
response = webwrite(uri, body, options);
%% HTTP Interface
import matlab.net.*
import matlab.net.http.*
import matlab.net.http.io.*
header = HeaderField('Content-Type', 'application/x-www-form-urlencoded');
uri = URI('http://a.com');
body = JSONProvider(123);
response = RequestMessage('post', [], body).send(uri.EncodedURI);
response = RequestMessage('post', header, body).send(uri.EncodedURI);

View File

@@ -1,13 +1,15 @@
%% Web Access using Data Import and Export API
uri = 'http://example.com/';
body = 'foo=bar&foo=&foo=barbar';
response = webwrite(uri, body);
options = weboptions('MediaType', 'application/x-www-form-urlencoded');
response = webwrite(uri, body, options);
%% HTTP Interface
import matlab.net.*
import matlab.net.http.*
import matlab.net.http.io.*
header = HeaderField('Content-Type', 'application/x-www-form-urlencoded');
uri = URI('http://example.com/');
body = FormProvider('foo', 'bar', 'foo', '', 'foo', 'barbar');
response = RequestMessage('post', [], body).send(uri.EncodedURI);
response = RequestMessage('post', header, body).send(uri.EncodedURI);

View File

@@ -1,13 +1,15 @@
%% Web Access using Data Import and Export API
uri = 'http://example.com/post';
body = 'msg1=wow&msg2=such&msg3=@rawmsg';
response = webwrite(uri, body);
options = weboptions('MediaType', 'application/x-www-form-urlencoded');
response = webwrite(uri, body, options);
%% HTTP Interface
import matlab.net.*
import matlab.net.http.*
import matlab.net.http.io.*
header = HeaderField('Content-Type', 'application/x-www-form-urlencoded');
uri = URI('http://example.com/post');
body = FormProvider('msg1', 'wow', 'msg2', 'such', 'msg3', '@rawmsg');
response = RequestMessage('post', [], body).send(uri.EncodedURI);
response = RequestMessage('post', header, body).send(uri.EncodedURI);

View File

@@ -1,13 +1,15 @@
%% Web Access using Data Import and Export API
uri = 'http://example.com/';
body = 'foo="bar"';
response = webwrite(uri, body);
options = weboptions('MediaType', 'application/x-www-form-urlencoded');
response = webwrite(uri, body, options);
%% HTTP Interface
import matlab.net.*
import matlab.net.http.*
import matlab.net.http.io.*
header = HeaderField('Content-Type', 'application/x-www-form-urlencoded');
uri = URI('http://example.com/');
body = FormProvider('foo', '"bar"');
response = RequestMessage('post', [], body).send(uri.EncodedURI);
response = RequestMessage('post', header, body).send(uri.EncodedURI);

View File

@@ -1,13 +1,15 @@
%% Web Access using Data Import and Export API
uri = 'http://example.com/';
body = 'foo="bar"';
response = webwrite(uri, body);
options = weboptions('MediaType', 'application/x-www-form-urlencoded');
response = webwrite(uri, body, options);
%% HTTP Interface
import matlab.net.*
import matlab.net.http.*
import matlab.net.http.io.*
header = HeaderField('Content-Type', 'application/x-www-form-urlencoded');
uri = URI('http://example.com/');
body = FormProvider('foo', '"bar"');
response = RequestMessage('post', [], body).send(uri.EncodedURI);
response = RequestMessage('post', header, body).send(uri.EncodedURI);

View File

@@ -1,13 +1,15 @@
%% Web Access using Data Import and Export API
uri = 'http://example.com/';
body = 'foo=''bar''';
response = webwrite(uri, body);
options = weboptions('MediaType', 'application/x-www-form-urlencoded');
response = webwrite(uri, body, options);
%% HTTP Interface
import matlab.net.*
import matlab.net.http.*
import matlab.net.http.io.*
header = HeaderField('Content-Type', 'application/x-www-form-urlencoded');
uri = URI('http://example.com/');
body = FormProvider('foo', '''bar''');
response = RequestMessage('post', [], body).send(uri.EncodedURI);
response = RequestMessage('post', header, body).send(uri.EncodedURI);

View File

@@ -2,7 +2,10 @@
uri = 'http://awesomeurl.com/upload';
body = fileread('new_file');
body(body==13 | body==10) = [];
options = weboptions('RequestMethod', 'put');
options = weboptions(...
'RequestMethod', 'put',...
'MediaType', 'application/x-www-form-urlencoded'...
);
response = webwrite(uri, body, options);
%% HTTP Interface
@@ -10,7 +13,8 @@ import matlab.net.*
import matlab.net.http.*
import matlab.net.http.io.*
header = HeaderField('Content-Type', 'application/x-www-form-urlencoded');
uri = URI('http://awesomeurl.com/upload');
body = fileread('new_file');
body(body==13 | body==10) = [];
response = RequestMessage('put', [], body).send(uri.EncodedURI);
response = RequestMessage('put', header, body).send(uri.EncodedURI);

View File

@@ -1,8 +1,13 @@
var request = require('request');
var headers = {
'Content-Type': 'application/x-www-form-urlencoded'
};
var options = {
url: 'http://localhost:28139',
method: 'POST'
method: 'POST',
headers: headers
};
function callback(error, response, body) {

View File

@@ -1,10 +1,15 @@
var request = require('request');
var headers = {
'Content-Type': 'application/x-www-form-urlencoded'
};
var dataString = 'foo=\"bar\"';
var options = {
url: 'http://example.com/',
method: 'POST',
headers: headers,
body: dataString
};

View File

@@ -1,10 +1,15 @@
var request = require('request');
var headers = {
'Content-Type': 'application/x-www-form-urlencoded'
};
var dataString = 'foo=\\\'bar\\\'';
var options = {
url: 'http://example.com/',
method: 'POST',
headers: headers,
body: dataString
};

View File

@@ -1,10 +1,15 @@
var request = require('request');
var headers = {
'Content-Type': 'application/x-www-form-urlencoded'
};
var dataString = '{"title":"china1"}';
var options = {
url: 'http://localhost:28139/post',
method: 'POST',
headers: headers,
body: dataString
};

View File

@@ -1,10 +1,15 @@
var request = require('request');
var headers = {
'Content-Type': 'application/x-www-form-urlencoded'
};
var dataString = 'msg1=wow&msg2=such&msg3=@rawmsg';
var options = {
url: 'http://example.com/post',
method: 'POST',
headers: headers,
body: dataString
};

View File

@@ -1,10 +1,15 @@
var request = require('request');
var headers = {
'Content-Type': 'application/x-www-form-urlencoded'
};
var dataString = 'foo="bar"';
var options = {
url: 'http://example.com/',
method: 'POST',
headers: headers,
body: dataString
};

View File

@@ -1,10 +1,15 @@
var request = require('request');
var headers = {
'Content-Type': 'application/x-www-form-urlencoded'
};
var dataString = 'foo="bar"';
var options = {
url: 'http://example.com/',
method: 'POST',
headers: headers,
body: dataString
};

View File

@@ -1,10 +1,15 @@
var request = require('request');
var headers = {
'Content-Type': 'application/x-www-form-urlencoded'
};
var dataString = 'foo=\'bar\'';
var options = {
url: 'http://example.com/',
method: 'POST',
headers: headers,
body: dataString
};

View File

@@ -1,10 +1,15 @@
var request = require('request');
var headers = {
'Content-Type': 'application/x-www-form-urlencoded'
};
var dataString = '{"admins":{"names":[], "roles":[]}, "readers":{"names":["joe"],"roles":[]}}';
var options = {
url: 'http://localhost:5984/test/_security',
method: 'PUT',
headers: headers,
body: dataString,
auth: {
'user': 'admin',

View File

@@ -1,5 +1,8 @@
var fetch = require('node-fetch');
fetch('http://localhost:28139', {
method: 'POST'
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
});

View File

@@ -28,6 +28,7 @@
]
],
"compressed": true,
"method": "get",
"headers": [
[
"Accept-Encoding",
@@ -57,6 +58,5 @@
"Connection",
"keep-alive"
]
],
"method": "get"
]
}

View File

@@ -1,14 +1,18 @@
{
"url": "http://fiddle.jshell.net/echo/html/",
"urlWithoutQuery": "http://fiddle.jshell.net/echo/html/",
"method": "get",
"data": "msg1=value1&msg2=value2",
"headers": [
[
"Origin",
"http://fiddle.jshell.net"
],
[
"Content-Type",
"application/x-www-form-urlencoded"
]
],
"method": "get",
"data": "msg1=value1&msg2=value2",
"dataArray": [
"msg1=value1",
"msg2=value2"

View File

@@ -16,6 +16,7 @@
]
],
"compressed": true,
"method": "post",
"headers": [
[
"Origin",
@@ -53,6 +54,5 @@
"Content-Length",
"0"
]
],
"method": "post"
]
}

View File

@@ -2,6 +2,8 @@
"url": "http://fiddle.jshell.net/echo/html/",
"urlWithoutQuery": "http://fiddle.jshell.net/echo/html/",
"compressed": true,
"method": "post",
"data": "msg1=wow&msg2=such",
"headers": [
[
"Origin",
@@ -39,7 +41,5 @@
"Connection",
"keep-alive"
]
],
"method": "post",
"data": "msg1=wow&msg2=such"
]
}

View File

@@ -3,6 +3,9 @@ $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'google.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type' => 'application/x-www-form-urlencoded',
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'field=don%27t%20you%20like%20quotes');
$response = curl_exec($ch);

View File

@@ -3,6 +3,9 @@ $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://example.com/post');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type' => 'application/x-www-form-urlencoded',
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'msg1=wow&msg2=such&msg3=@rawmsg');
$response = curl_exec($ch);

View File

@@ -6,6 +6,7 @@ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'A' => '\'\'a\'',
'B' => '"',
'Content-Type' => 'application/x-www-form-urlencoded',
]);
curl_setopt($ch, CURLOPT_COOKIE, 'x=1\'; y=2"');
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);

View File

@@ -3,6 +3,9 @@ $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://localhost:5984/test/_security');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type' => 'application/x-www-form-urlencoded',
]);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, 'admin:123');
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"admins":{"names":[], "roles":[]}, "readers":{"names":["joe"],"roles":[]}}');

View File

@@ -1,5 +1,9 @@
import requests
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
}
data = 'version=1.2&auth_user=fdgxf&auth_pwd=oxfdscds&json_data={ "operation": "core/get", "class": "Software", "key": "key" }'
response = requests.post('https://cmdb.litop.local/webservices/rest.php', data=data)
response = requests.post('https://cmdb.litop.local/webservices/rest.php', headers=headers, data=data)

View File

@@ -1,3 +1,7 @@
import requests
response = requests.post('http://localhost:28139')
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
}
response = requests.post('http://localhost:28139', headers=headers)

View File

@@ -1,5 +1,9 @@
import requests
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
}
data = 'foo=\\"bar\\"'
response = requests.post('http://example.com/', data=data)
response = requests.post('http://example.com/', headers=headers, data=data)

View File

@@ -1,5 +1,9 @@
import requests
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
}
data = 'foo=\\\'bar\\\''
response = requests.post('http://example.com/', data=data)
response = requests.post('http://example.com/', headers=headers, data=data)

Some files were not shown because too many files have changed in this diff Show More