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:
Related
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.
I'm having one Rest API: /myApp/fetchData/User-Name/Password. User-Name and Password will be changed based on the request.
When i call the above restapi like this
/myApp/fetchData/srikanth/Abcdef#g123
the request is going like this:
/myApp/fetchData/srikanth/Abcdef
Basically in the URL text got removed from # character. Is there any way to solve?
Thanks,
Srikanth.
In a URI the # triggers the begins of the "fragment", and ends the path. The fragment usually specify a portion of the resource identified by the path.
When you are post-ing the request from the client, you have to escape special characters. Your request should be:
/myApp/fetchData/srikanth/Abcdef%23g123
There are different way to escaping urls, like the encodeURI or encodeURIComponent function in JS. For example, you may do:
var request = "/myApp/fetchData/srikanth/" + encodeURIComponent("Abcdef#g123");
Then the server have to decode back to the original request.
But: are you sure it is a good solution to send the password plain in that way?
I currently just show the JSON in my template with
<pre>{{ mydata | json }}</pre>
I like to add a button for users to download the json data.
Is there an easy way to do this ?
Downloading the JSON data, means downloading a file containing a JSON string.
If you are already able to render that file on the server, then you just need to create an html link, with the href attribute pointing to the corresponding server url.
In order to force the file to be downloaded, you have to declared it as an attachment in an http header.
The response must contains something like this:
'Content-Disposition: attachment; filename=data.json'
You can also specify the content-type with another response header:
'Content-Type': application/json
Edit: I just discovered that apparently you can initialize a file download directly from the client. See this SO topic. Seems to be pretty well supported: http://caniuse.com/#feat=bloburls
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
In CakePHP I have a rss view that is requested on http://example.com/file.rss. Because of Router::parseExtensions('rss') the contents are correctly handled as xml/rss.
Now I'm using $this->cacheAction to cache the request. Everything works fine: rss contents are generated and the cache file is created after the first request.
But the following problem occurs: the first request returns a header Content-type: application/rss+xml (which is correct). The second request (which is the result of the cached view) returns a totally different header Content-type: text/html. But why? How can I make sure to always get the rss header?
I'm using the latest version of CakePHP 2.3.
I already tried to set the header in the rss layout file default.ctp by adding
// ...
?><!--nocache--><?php
header('Content-type: application/rss+xml');
?><!--/nocache--><?php
// ...
and similar code snippets, but without success. The response header is still the html content type.