Error by reading Header values from Logic App HTTP Request - azure-logic-apps

In a if condition I tried to get a header value (secret key) I'am sending to the Logic App.
The following code is used to get the secret from the header (In this example i have parsed it before)
#body('Parse_Header_from_HTTP_Request')?['headers']?['Secret']
I have also tried the solution from this answered question:
Azure Logic Apps : Get HTTP Request Header Key Value into Conditional Check
The variable is null if I check it on the Run History.

According to your description, I do not know how you parse your header before.
Here I use Parse Json to achieve, you could refer to the screenshot as below:
After setting body('Parse_Json')?['name'] to get name value, the output is as below:
As you have said, you have parsed the header after http request. So, after parsing headers, the value is from parse_json, while you refer to the link you provided which value is from http request header.
Hope it helps you.

Related

How to get actual image from image path in http response?

I am making a http request which responds back with an image path like so
{
poster-path: /heb234gdb.jpg
}
I tried adding this path to the end of the same http request, removing everything else and using this path at the end of the main api url, simply using this path and a lot more but I can't get the image to show. What is the way to do this?
P.S.: I did not give the api urls purposely but if any more info is needed please comment
First of all , Edit your question!.
You can have the description in Code Snippet ,its annoying.
Like #jessy said I had to read the documentation and I found a completely separate API's link at the end of which I had to add the path to get the image.

AngularJS $http service has CORS issue. But it should be working for JSONP, right? [duplicate]

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.

Superagent: PUT-ing multipart form data

Is it possible to do a PUT request with multipart form data?
With Superagent I would expect the following to work, but it doesn't.
var request = Request
.put("http://localhost:8080/upload_file")
.field("name", file.name)
.field("size", file.size)
.attach("file", file.file, file.file.name)
.accept("application/json")
If I do a post, it works. The difference is the Content-Type. With the successful post request the Content-Type is multipart/form-data; boundary=------WebKitFormBoundaryXg34NkBFcYWq60mH.
If I were to set this manually how would I know what the boundary should be? It seems to be automatically generated by Superagent.
You should probably do a POST, per Tum's comment.
If I were to set this manually how would I know what the boundary should be? It seems to be automatically generated by Superagent.
You should let Superagent manage that by itself - don't try to set the type yourself, leave off the type call and it will include the correct boundary identifier when it sets it as multi-part itself.
No, it is not possible to do a PUT request with content-type multipart/form-data due to an underlying limitation in PHP as discussed here: https://bugs.php.net/bug.php?id=55815
You might want to take a look at a 'hack' that was done for Symfony in Chekote/symfony: https://github.com/Chekote/symfony/commit/dc1279b2e4c0e9cbcb5b7d578891c31dd878b43b

can not get headers from response in Ext.Ajax.request success callback

I am using Ext.Ajax.request(in sencha toucn 2.3) to post data to my backend server.
And i want to read some custom headers from the "response" parameter of the "success" callback like this:
response.getResponseHeader('x-user-session');
i am quite sure the backend server send back many headers and the 'x-user-session' header also present, but what strange is: when using the "response" object, i can get only one header : "content-type".
this question has already been asked here: ExtJS 4.2.1: Cannot retrieve HTTP Response headers upon Ext.ajax.request callback , but there is no answer yet.
I have already tried debug into the "Ext.data.Connection" class, and found the headers of "response" object in "Ext.data.Connection" also contains only "content-type" header.
could anybody tell me why this happened? is there something wrong in my backend program? or just a bug of Ext.Ajax? how can i get the value of my custom header 'x-user-session'?
thanks ~~
==================ANSWER=====================
i finally got the answer from sencha forum: http://www.sencha.com/forum/showthread.php?289879-the-response-for-Ext.Ajax.request-doesn-t-include-all-response-headers
here is the part about the headers:
Access-Control-Expose-Headers (optional) -
The XMLHttpRequest 2 object has a getResponseHeader() method that returns the value of
a particular response header. During a CORS request, the getResponseHeader() method
can only access simple response headers.
Simple response headers are defined as follows:
Cache-Control
Content-Language
Content-Type
Expires
Last-Modified
Pragma
If you want clients to be able to access other headers, you have to use the
Access-Control-Expose-Headers header. The value of this header is a comma-delimited
list of response headers you want to expose to the client.
i haven't verify it yet, but it seems on the right track :)
enclosed the screen captures:

How to rewrite function used POST metod to use also GET method in LoadRunner?

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&param2=value2...&paramN=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.

Resources