mirror of
https://github.com/ProxymanApp/Proxyman.git
synced 2026-04-26 00:25:56 +03:00
[GH-ISSUE #1193] How to send HTTP requests in onResponse in scripting Menu #1189
Labels
No labels
Discussion
Feature request
In Progress...
Plugins
Waiting response
Windows
Windows
bug
duplicate
enhancement
feature
good first issue
iOS
macOS 10.11
question
wontfix
✅ Done
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/Proxyman#1189
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @1414044032 on GitHub (Mar 30, 2022).
Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/1193
Originally assigned to: @NghiaTranUIT on GitHub.
Proxyman version? (Ex. Proxyman 1.4.3)
Proxyman 1.4.3
macOS Version? (Ex. mac 10.14)
mac 12.2.1
Steps to reproduce
Writing your own scripts for Scripting
Expected behavior
Proxyman provides Base64 lodash and other scripts.
But I want to send the network request through the Node HTTP module in the onResponse function.
I found that I couldn't use any of the built-in modules in Node. It prints undefined。
I want to process the data in onResponse and send it to an address via an HTTP request。
Screenshots (optional)
@NghiaTranUIT commented on GitHub (Mar 30, 2022):
Currently, it's not possible to make an async API call in the
onResponse()because it's a sync function.Can you elaborate on what network request you'd like to use? I might bring
axiosorfetchif it's possible@1414044032 commented on GitHub (Mar 30, 2022):
It would be best to support Axios to send requests.
I don't really care if the request succeeds, I just want to push some data parsed in onResponse to my webHook address.
For example:
OnResponse might parse out some of the data, which I can push to a Web address on my own server via axios.
As for whether the request was successfully sent to my server, whether my server returned a status code of 200 is actually not my concern.
I think this feature will be great because there are limitations to what developers can do in Scripting right now.
----The translation is from Youdao Dictionary
@michael-elkabetz commented on GitHub (Apr 6, 2022):
i found my self need this ability also @NghiaTranUIT, once received response i want to send an http request using Axios/http/curl to my server to get slack notification sync/async its irrelevant for me either.
@NghiaTranUIT currently there is any way to do it?
@NghiaTranUIT commented on GitHub (Apr 7, 2022):
Unfortunately, there is no way to perform an Async call in the scripting at the moment.
The JS Context is going to release as soon as the script is called.
I'm going to support Async soon 👍
@michael-elkabetz commented on GitHub (Apr 19, 2022):
Hey @1414044032, @NghiaTranUIT,
I tried to add this ability by myself and unfortunately failed, hope that you will be able to assist.
I think i have tried any axios.js version out there, here are my finding.
The best result i achieved was with axios version 0.14 and 0.13.
I got my console.log message printed inside my axion.get('..').than, but it seems like the request was not actually executed. the data i had inside was:
{"transformRequest":{},"transformResponse":{},"headers":{"Accept":"application/json, text/plain, */*"},"timeout":0,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","maxContentLength":-1,"method":"get","url":"http://webcode.me"}In any version 0.15 and above i got the following error:
adapter is not a function. (In 'adapter(config)', 'adapter' is undefined)In any version older than 0.13 i didn't receive an error however nothing was printed or triggered.
below you can find my code snippet:
`const axios = require('@libs/axios.js');
function onRequest(context, url, request) {
return request;
}
function onResponse(context, url, request, response) {
response.headers["Content-Type"] = "application/json";
axios.get("http://webcode.me")
.then(function(response) {
console.log("data: " + JSON.stringify(response));
})
.catch(function(error) {
console.log("error:" + error);
})
return response;
}`
@1414044032 commented on GitHub (Apr 20, 2022):
I think add this function only by author. Axios in node env will use HTTP module to send request. But in this application NODE env is broken. That's my guess.
@NghiaTranUIT commented on GitHub (Apr 20, 2022):
Hey guys. I'm working on this feature by inspiring from the Scriptable app.
See this Request: https://docs.scriptable.app/request/#-loadjson
Basically, we can
@michael-elkabetz commented on GitHub (Apr 21, 2022):
You mean that once the feature will be ready this is the way we will be able to execute requests?
@NghiaTranUIT commented on GitHub (Apr 21, 2022):
@whyike yes. You can consume Restful APIs 👍
@NghiaTranUIT commented on GitHub (May 1, 2022):
The good news is that I finally found a solution that allows you to consume a Restful API 😄
I'm working on it, and will soon send you guys a Beta build soon 🙌
@michael-elkabetz commented on GitHub (May 1, 2022):
@NghiaTranUIT you are truly amazing dear!!!! waiting for that!!!!
@michael-elkabetz commented on GitHub (May 12, 2022):
Any updates dear @NghiaTranUIT?
@NghiaTranUIT commented on GitHub (May 12, 2022):
@whyike @1414044032 you might this Beta build: https://proxyman.s3.us-east-2.amazonaws.com/beta/Proxyman_3.4.0_Async_HTTP_Request_on_Scripting.dmg
Note
async onRequest()orasync onResponse()await $http.get()/await $http.post()/await $http.delete()/await $http.update()"Content-Type": "application/json"for JSON Body.Sampe code
Screenshots
@michael-elkabetz commented on GitHub (May 12, 2022):
Amazing! @NghiaTranUIT, testing it right away!
@michael-elkabetz commented on GitHub (May 12, 2022):
It is working amazing!!!
Thanks a lot!!!!! @NghiaTranUIT
@NghiaTranUIT commented on GitHub (May 13, 2022):
Here is the final Beta buid: https://proxyman.s3.us-east-2.amazonaws.com/beta/Proxyman_3.4.0_Support_Async_$http.get.dmg
@1414044032 commented on GitHub (May 22, 2022):
It's such a great feature。I gave it a try and it met my needs very well. Thanks to the authors for their development work