I have implemented a bounce handler by copying the code from the documentation, but now I would like to test that this code works before I push it out to production. Is there an easy way to do this?
I wound up using a Chrome extension called POSTMan to formulate a POST request with all of the required parameters, as shown in the docstring of the BounceNotification class:
post_vars: a dict-like object containing bounce information.
This is typically the self.request.POST variable of a RequestHandler
object. The following keys are expected in the dict:
original-from
original-to
original-subject
original-text
notification-from
notification-to
notification-subject
notification-text
raw-message
When I sent all of the required POST params, I indeed saw my bounce handler get the request and log the appropriate information.
Related
I'm trying to get the URL of any attachments in a message. I can't seem to find a way to do this: whenever I try to run console.log(message.attachments.url), it just outputs undefined. What am I doing wrong?
I've tried reading the docs and other Stack Overflow questions but nothing worked.
I expect the output to be a URL of the attachment, i.e. 'https://cdn.discordapp.com/attachments/serverid/channelid/file.png' However, it just outputs undefined.
message.attachments is a Collection (a Map with additional Utility functions) so you either have to get the specific attachment via message.attachments.get('ID') or if you are sure that the message only has one attachment you can use message.attachments.first(). Otherwise you have to iterate through the Collection via
message.attachments.forEach(attachment => {
// do something with the attachment
const url = attachment.url;
});
I linked to the Collection docs of Discord.js. You also have access to the typical Map functions as well.
You read that right, this is AngularJS, the old one.
I have an Angular $http.post that returns an object with various values including a fairly large dictionary of more objects that map to a bunch of fields on a spreadsheet.
The magic:
If I debug the backend (.NET) and look at the object being returned all is well and as expected. If I log out the res.data object right after it is returned in the JS callback there is one particular (possibly more) string value within that dictionary of objects I mentioned that is set from "Some text" to "". No errors, no warnings...
But get this... if I look at the response in Fiddler THE VALUE IS THERE.
The discovery:
If I do a Request for only that Dictionary of Objects rather than it plus other data the value does indeed appear. Cool, so I can work around this... But WHY?
Why would this happen? Is there some size cap on response objects to Angulars $http.post? I am passing in no options to the post and I cannot find any info on this.
Thanks for any ideas!
UPDATE: (Code has been requested)
$http.post(baseUrl + "TESTCompData?p1=" + p1 + "&c1=" + c1).then(function (res) {
console.log(res);
})
The dictionary object I'm referring to:
public Dictionary<string, Dictionary<string,object>> ControlData;
The object in question:
{txt_SomeTexty: {
LineItemDataID=998,
LineItemMetaDataID=325,
SectionID=11,
Value=Some Text for XX (not a abc): $999,999,999}}
Value here comes in blank.
Figured it out though.
Turns out I was just accidentally clearing the field during a transformation method I had.
But what I don't understand: I was console.log'ing the object BEFORE this took place yet I saw it changed there. See I expected the logged object to be what it was when the response was returned (since that's where the log was) but somehow it isn't... it's the updated version.
I'm trying to load an external page using JSONP, but the page is an HTML page, I just want to grab the contents of it using ajax.
EDIT: The reason why I'm doing this is because I want to pass all the user information ex: headers, ip, agent, when loading the page rather than my servers.
Is this doable? Right now, I can get the page, but jsonp attempts to parse the json, returning an error: Uncaught SyntaxError: Unexpected token <
Sample code:
$.post('http://example.com',function(data){
$('.results').html(data);
},'jsonp');
I've set up a jsfiddle for people to test with:
http://jsfiddle.net/8A63A/1/
http://en.wikipedia.org/wiki/JSONP#Script_element_injection
Making a JSONP call (in other words, to employ this usage pattern),
requires a script element. Therefore, for each new JSONP request, the
browser must add (or reuse) a new element—in other words,
inject the element—into the HTML DOM, with the desired value for the
"src" attribute. This element is then evaluated, the src URL is
retrieved, and the response JSON is evaluated.
Now look at your error:
Uncaught SyntaxError: Unexpected token <
< is the first character of any html tag, probably this is the start of <DOCTYPE, in this case, which is, of course, invalid JavaScript.
And NO, you can't use JSONP for fetching html data.
I have done what you want but in my case I have control of the server side code that returns the HTML.
So, what I did was wrapped the HTML code in one of the Json properties of the returned object and used it at client side, something like:
callback({"page": "<html>...</html>"})
The Syntax error you are facing it's because the library you're using expects json but the response is HTML, just that.
I've got three words for you: Same Origin Policy
Unless the remote URL actually supports proper JSONP requests, you won't be able to do what you're trying to. And that's a good thing.
Edit: You could of course try to proxy the request through your server …
If you really just want to employ the client to snag an HTML file, I suggest using flyJSONP - which uses YQL.. or use jankyPOST which uses some sweet techniques:
jankyPOST creates a hidden iframe and stuffs it with a form (iframe[0].contentWindow.document.body.form.name).
Then it uses HTML5 (watch legacy browsers!) webMessaging API to post to the other iframe and sets iframe's form elements' vals to what u specified.
Submits form to remote server...done.
Or you could just use PHP curl, parse it, echo it, so on.
IDK if what exactly ur using it for but I hope this helps.
ALSO...
I'm pretty sure you can JSONP anything that is an output from server code. I did this with ClientLogin by just JSONPing their keyGen page and successfully consoleLogged the text even though it was b/w tags. I had some other errors on that but point is that I scraped that output.
Currently, I'm trying to do what you are so I'll post back if successful.
I don't think this is possible. JSONP requires that the response is rendered properly.
If you want another solution, what about loading the url in an iframe and trying to talk through the iframe. I'm not 100% positive it will work, but it's worth a shot.
First, call the AJAX URL manually and see of the resulting HTML makes sense.
Second, you need to close your DIV in your fiddle example.
I'm trying to catch some POST-request, log a message (and maybe a body or params in future); then pass them further to booHost, so the client will get the result of the call:
from("restlet:http://localhost:8090/api/endpointFoo?restletMethod=post")
.log("oh, it's a message!")
.routeId("someAPI")
.to("http://booHost:8090/api/endpointFoo?bridgeEndpoint=true&restletMethod=post");
That works just GREAT.
But:
What I need is the URL-pattern that will work that way. I'm trying:
from("restlet:http://localhost:8090/api/{endpoint}?restletMethod=post")
.log("oh, it's a message!")
.routeId("someAPI")
.to("http://booHost:8090/api/{endpoint}?bridgeEndpoint=true&restletMethod=post");
The "from" shots when I make the post. The message is logged.
But "to" seems not to treat {endpoint} as a param - it treats it like a constant; so the result of that call fails.
I don't need hardcoded endpoints because booHost API should be extended in future without Camel changes.
In other words, I need all calls to http://localhost:8090/api/* to be catched and resent to http://booHost:8090/api/* on the same endpoint.
Maybe I should use another component? Or How can I make it this way?
Thanks.
Thanks to #vikingsteve I've started to read about recipientList.
I've modified my code according to this FAQ question
The final version looks like this:
from("restlet:http://localhost:8090/api/{endpoint}?restletMethod=post")
.log(LoggingLevel.INFO, "POST-request to /${headers.endpoint} was sent")
.routeId("someAPI")
.recipientList(simple("http://booHost:8090/api/${headers.endpoint}?bridgeEndpoint=true&restletMethod=post"));
It works as suggested.
For POST method I have this piece of code in LR (it is working):
web_custom_request(transname,
URL,
"Method=POST",
"TargetFrame=",
"Mode=HTML",
"Resource=0",
"Referer=",
EncodingType,
lr_eval_string(request),
LAST);
This piece of code is placed in a separated .c file and called from user_init using a long sequence of related functions working with XML, arrays, strings data.
URL for POST requests has structure in user_init like this:
URL=https://{HOST}/aaa/bbb/page.asp
Also user_init contains this piece of code:
web_custom_request("Login_page",
"URL=http://{HOST}/api/04_00/Pr_NAME.asp",
"Method=POST",
"RecContentType=text/xml",
"Body="
"<?xml version=\"1.0\"?>"
"<Request xmlns=\"http://api.rr.com/Pr_NAME\">\r\n"
" <MethodRequest>\r\n"
" <AuthenticateUserRequest appID=\"value_appID\" password=\"value_password\">\r\n"
" <User>\r\n"
" <LoginName>value_LoginName</LoginName>\r\n"
" </User>\r\n"
" </AuthenticateUserRequest>\r\n"
" </MethodRequest>\r\n"
"</Request>\r\n",
LAST);
I need something additional to this code, that will allow to send both POST and GET requests to web-service. Now it sends only POST requests.
There are some questions:
1) How should I change this function to get the possibility to send both types of requests, POST and GET? What strings should I add to this function?
2) How should I change the URL for GET requests?
I think, it should be something like this:
URL=https://{HOST}/aaa/bbb/page.asp?param1=value1¶m2=value2...¶mN=valueN
But what parameters should I add as param1, param2, ..., paramN?
How to define, how many and what parameters I need put in this URL construction?
Should I write this structure:
URL=http://{HOST}/api/04_00/Pr_NAME.asp?appID=value_appID&password=value_password&LoginName=value_LoginName
or shouldn't I add LoginName=value_LoginName in this structure?
3) How can I combine both 2 methods POST and GET in 1 function, to have the possibility to send both types of requests, POST and GET, from LR?
Please, could you help me? I'm a novice in data transferring in LR using POST and GET methods and functions.
Here are some answers (not entirely related to LR).
1) POST and GET are HTTP verbs that tell the server what you expect it to do with your request. There is no rules on what the server should do but instead conventions. The conventions are:
GET - Tells the server: Please give me data related to the parameters I provide in the querystring.
POST - Tells the server: Here is some data in the body of this request, please do something with it (usually but not always create a record of something).
There is no sense of sending both types of verbs in the same request.
In any case to set the verb use the "method" parameter (in your example it says "Method = POST" so you can change it to "Method = GET".
2)GET request sometimes needs parameters. As a convention you don't send those parameters in the Body but in a structure called querystring which comes after the URL separated by "?". The querystring is a list of parameter name and its value. Please google "querystring" for more information. The parameters you should use are the ones expected by the server. You have to ask the server creator about which parameters to send.
3) As I mentioned above, this doesn't make sense.
Hope this helps.
Since you likely have recorded this conversation, the natural question to ask why you would want to alter the request method in your application code to something else other than what is deployed? This is a break in your test between deployed and test and would need to be noted with your test results.
Requests' method should either POST or GET or other types of methods. There should NOT be both. I understand that you are doing self-study, but it is protocol violation.