View Raw JSON File in Browser - json

I'm writing an iOS app which will eventually retrieve data in JSON from a web service. However, before I get the web service running, I just want to test the app's ability to retrieve the JSON, so I thought I could simply upload a dummy JSON file (.json) to the root of a website I have hosted, point my browser to that file's URL and view (or at least download) the JSON.
Unfortunately, when I try to navigate to the JSON file's URL in my browser, I get the message
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
If I use the same URL in Postman I get a different response:
The page you are looking for cannot be displayed because an invalid method (HTTP verb) is being used.
I realise I'm doing something stupid here and probably fundamentally misunderstanding something, but after quite a lot of Googling I don't know what! Everybody else with similar issues seems to reporting that they're prompted to download the JSON file rather than just seeing the data displayed in their browser, but I'm not even getting that. It'd be fine if I was! For what it's worth, I've verified the JSON itself in JSONLint.

Related

Getting file based on weird URI provided in manifest.json returns 404

I am trying to get all the files from autodesk forge using the GET object API
and there's one file that I am unable to download no matter what, the filename is
Finishes.Ceilings.Acoustical Tile.Perforated.2x2.White.jpg.
Link to manifest.json here
I have checked the URI and it looks extremely weird as compared to other files.
so... my question is that, is this a bug on Autodesk side or did I not do something correctly before translating my model to SVF?

Firefox: view raw JSON on network tab

I'm having a problem with Firefox's debugging panel, spcecifically on the Network tab; when a POST request sends some JSON, it shows the request body inside a tree-like viewer; while this viewer is cute and everything, I actually need to copy and paste the actual raw JSON text into another tool.
There doesn't seem to view the actual JSON request from this panel. Does someone know of some way of viewing the actual RAW JSON inside it?
After some fumbling around, I found out that if you right-click the request, the browser gives you the option to copy the post data (which would return the JSON, if it is a POST) or to "Edit and resend", which would open a dialog that, among other things, has the JSON itself.

How to use local JSON assets to simulate API in Scala.js

I'm new to Scala and Scala.js and I want to experiment with handling JSON data. I'd like to simulate a server response by returning the content of a JSON file local to my Scala.js project, parse it and work with the data. What would be the best way to do so? Where should I place these files in my project tree, and how would I get their content?
Say that I have a file called myJSON.json containing something like
[
{
"ress": "AR",
"lastDate": "2017-10-27 09:19:18"
},
{
"ress": "JIM",
"lastDate": "2017-10-27 06:57:15"
},
{
"ress": "JOE",
"lastDate": "2017-09-29 11:57:39"
}
]
Can I place this file somewhere in my project so that I can read this file and then parse its content to use it somehow (could be displayed in the browser, logged to the console, etc...)? I guess I could use a tool such as scala-js or something similar for parsing, but accessing the file content in the first place is what I try to figure out.
Note that I'm using scala-js.
Thanks in advance!
Like others said above, Javascript that runs in the browser in general can't access the local filesystem. There are some exceptions:
The File API lets you access files that the user has selected in the UI using <input type="file" /> or drag-and-dropped into the browser window.
The Filesystem API lets you access files the way you seem to want, but it is non-standard and is not supported in most browsers. It also seems that Scala.js has no typings for it, but I'm not sure.
scala-js-dom has typings for the File API that you can use – search for File and FileList types in its source. Its API mirrors the Javascript API, so you will need to look for how exactly to do this in JS. Then translating it into Scala.js will be easy (or at least a different question).
If the File API does not work for your use case, another option is to use something like json-server to easily serve your JSON files on localhost via HTTP.

How to download a file in Jmeter with just the original file content?

I'm working on functional testing of a REST API using Jmeter and JSON. I've got file uploading working but I cant seem to get the file downloading to work in jmeter. I'm saving the response as noted in this post: JMeter - File upload and file download scenario
When I do this, I am getting close but not quite exactly what I need. This is and example of what I am getting:
--0rVAdzesdQq7VrwJaRoYGm_UHdMD5nhi9_5w4u
Content-Disposition: form-data; name="api-test"; filename="LIBFILE1.txt"
Content-Type: text/plain
Content-Transfer-Encoding: binary
Library File for Automated Smoke Test
This file is used to test file library upload for automated smoke tests.
--0rVAdzesdQq7VrwJaRoYGm_UHdMD5nhi9_5w4u--
How can I get the download to only save the file contents? In this example, it should only be:
Library File for Automated Smoke Test
This file is used to test file library upload for automated smoke tests.
This is a simple textfile. I would also like to download the other formats that I'm uploading including jpg, png, docx, pdf but it wont be right if it has this extra data coming with it. I figure once I get a simple text file working, it will help me get the more difficult file types.
Well, Save Responses to a file listener will store the data you can observe in the "Response Data" tab of the View Results Tree listener. If you see these Content-Type, Content-Disposition, etc. headers as response data - most probably your upload wasn't successful as you should not be getting the headers this way.
I would recommend double checking that the same request being executed via browser or i.e. Postman tool returns the same response and fix your JMeter script in case of differences.
See Performance Testing: Upload and Download Scenarios with Apache JMeter article for details on how to properly mimic file operations with JMeter.
Alternative way of saving response data into a file is using JSR223 Listener, given you select "groovy" in the language dropdown you should be able to save the response using the following simple script:
new File("/path/to/your/file.txt").setBytes(prev.getResponseData())

How can I determine the real content type of an HTTP response with an incorrect one?

I'm trying to write an extension that corrects 'incorrect' content types. An example situation is a user might click on a link to a PDF file that has the HTTP Content-Type set to application/octet-stream. In this case, I want to be able to detect that the real content type is application/pdf.
A simple but not-so-robust way to do this would be to define my own mappings from file extensions to content types. However, it would be good if I could re-use existing work to do this.
I noticed that Chrome is able to determine how to display files obtained via the ftp and file protocols, which I don't believe provide content type information. How does Chrome do this? Does it inspect the file contents? Does it check the file extensions? Most importantly, can I programmatically hook into this content type detection functionality for my extension?