Skip to content

Commit 03b6f6a

Browse files
author
Shashi Ranjan
committed
custom method
1 parent 4658d45 commit 03b6f6a

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

‎src/targets/java/okhttp.js‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ module.exports = function (source, options) {
2222

2323
var methods = [ 'GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS' ]
2424

25-
if (methods.indexOf(source.method.toUpperCase()) === -1) {
26-
return 'Method not supported'
27-
}
28-
2925
code.push('OkHttpClient client = new OkHttpClient();')
3026
.blank()
3127

@@ -40,10 +36,18 @@ module.exports = function (source, options) {
4036

4137
code.push('Request request = new Request.Builder()')
4238
code.push(1, '.url("%s")', source.fullUrl)
43-
if (source.postData.text) {
44-
code.push(1, '.%s(body)', source.method.toLowerCase())
39+
if (methods.indexOf(source.method.toUpperCase()) === -1) {
40+
if (source.postData.text) {
41+
code.push(1, '.method("%s", body)', source.method.toUpperCase())
42+
}else {
43+
code.push(1, '.method("%s", null)', source.method.toUpperCase())
44+
}
4545
}else {
46-
code.push(1, '.%s()', source.method.toLowerCase())
46+
if (source.postData.text) {
47+
code.push(1, '.%s(body)', source.method.toLowerCase())
48+
}else {
49+
code.push(1, '.%s()', source.method.toLowerCase())
50+
}
4751
}
4852

4953
// Add headers, including the cookies
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
Method not supported
1+
OkHttpClient client = new OkHttpClient();
2+
3+
Request request = new Request.Builder()
4+
.url("http://mockbin.com/har")
5+
.method("PROPFIND", null)
6+
.build();
7+
8+
Response response = client.newCall(request).execute();

0 commit comments

Comments
 (0)