How to get to the JSON text using the VBnet standard browser - json

Sorry it is difficult to provide code for this.
In a normal browser (firefox, IE etc) when I enter a Google Geo Code API URL
https://maps.googleapis.com/maps/api/geocode/xml?address=&key=
with myAddress and mykey set correctly. I get a the JSON response as text in the browser window.
I would like to do exactly the same with a VBNet browser control. That is-
Set aBrowser.Navigate property to my Google GeoCode API URL and then receive the JSON back as text in the browser that can be accessed with aBrowser.document.... .
However, VBnet seems to immediately abort the url navigation task and invites the user via a dialogue box to save a file. If I save the file and then inspect it, the content is the JSON text that I expected to see inside the browser document.
This is my first play with JSON and assumed that the VBNet browser would behave just like IE. I am missing something?
Thanks in advance.
Geoff

Had a play with the answer provided for for HTTP GET in VB.NET
This is easily adapted to work with Google GEO Code API and the JSON text is received into a string. I can then either process the string or place the string on the browser page.
This works for me.

Related

Multiple arguments in a google Text to Speech api html GET request

I have a GET request in my code that gets an mp3 file from google's text to speech API. the request goes something like this.
api/getlink?word=testing
But I want to have multiple arguments in this request. Like a speakingRate argument. I have tried
api/getlink?word=testing,speakingRate=0.5
and
api/getlink?word=testing&speakingRate=0.5
but neither seem to work. I'm missing the right formatting or is this method just restricted to a single argument?

Can Firefox Inspect Element Network find json strings like Chrome can?

My intention is to analyze json strings as part of REST messages.
In Chrome there are possibilities to use Inspect -> tab Network to find the json string that I want. However I cannot find the json string in Firefox.
Does Firefox support this?
I will show an example from a public page.
Open https://www.theguardian.com/ in Chrome
Inspect (Ctrl-Shift-I) and select tab Network
Click UK (UK News)
On tab Response you will find json strings as for examlple comment-counts.json
like
{"counts":[
{"id":"/p/5kmed","count":269},{"id":"/p/5kkv8","count":39},
{"id":"/p/5kq4t","count":5},{"id":"/p/5k7x7","count":1064},
{"id":"/p/5ky88","count":1720},{"id":"/p/5kp8e","count":841},
{"id":"/p/5kkbv","count":692}]
}"
Image: Inspecting The Guardian UK News
In Firefox I cannot get this piece of code. I have tried Inspect Element tab Network and sub-tabs Headers, Params and Response.
Do anyone know if it is possible in Firefox and in that case how to get it?
Background: I'm working in a corporate linux system where I haven't authority to install so much. However I have access to Firefox 45.5.1 and a bad build of Chrome 43.0.2357.81.
Thanks for any idea you come up with.
AFAIK, Firefox currently offers only a "structured view" of JSON responses in the developer tools.
There is a ticket in Bugzilla requesting plain text view.
Not sure about Firefox 45, but the latest release offers a context menu entry which allows copying response text to clipboard. Maybe that helps.
With Rafael's answer I found out what I needed.
Sometimes Copy Response works fine.
When that does not work I can find what I need from Copy All As HAR, which contains more or less everything before "now".
Since I'm a newbie I can neither flag up Rafaels answer nor flag that this question has been answered.
From my perspective I am fully satisfied and the case can be closed.

Firefox requests XML and IE requests JSON from my Web API website, what to change browser's setting?

I have a ASP.NET Web API website, sometimes I just want to see the data returned by HTTP GET. While I know how to get XML or JSON through programming, I don't know where to change the browser's settings (IE, Firefox, and Chrome) to request XML or JSON?
ASP.NET Web API returns JSON or XML based on Accept header.
Different browsers have different default Accept headers. As for me:
Firefox:
text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1
As text/xml is the most preferable, WebAPI returns XML for Firefox.
IE:
application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
Chrome:
*/*
Since XML and JSON are equally acceptable, WebAPI chooses JSON.
How to change these settings
IE generates Accept header value based on registry keys:
HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Accepted Documents
Firefox stores it in a variable Network.http.accept.default.
You can change it in about:config tab.
I haven't found an information about Chrome. Probably, you can use ModHeader extension to do this.
I am building a WebAPI using Visual Studio 2015.
I'm using Firefox to test it.
I ran the basic project and attempted to call the following WebAPI request to get an object back (serialized as JSON).
When I made the call via Firefox I got an error because Firefox requests XML and WebAPI attempts to default the object to JSON but has no concept for auto-generating the XML.
Resolution
To Fix this you have to go to the Navigation bar of firefox and type :
about:config<ENTER>
You will see a warning screen. Click the button to continue.
You will then see a list of configurable items.
We want the network.http.accept.default.
It's easiest to find if you type the word accept in the top search bar.
Once you find that item. Double-click it and you will be able to edit it.
We just want to add a value that will tell it request JSON as the default.
This header will tell the server that JSON is okay. Since the WebAPI test does not set a specific type to return it allows the browser to control it.
When you double-click the item a dialog box with a edit box will popup.
You want to simply add the following string to the beginning of the existing string.
application/json,
Make sure you give it a trailing comma to separate it from the other existing values. Click the OK button.
As soon as you make that change (clicking OK to finalize it) you can go back to your original tab and make the call to the API method again and it will return JSON as you expect.

HTML5 speech input and Google Translate text-to-speech, problem in Chrome

I'm creating a voice/text-memo web application.
Here: http://gustavstromberg.se/sandbox/html5/localstorage/ look at its source (very short, most of it is css)
This is:
Voice recognition, works only in chrome as far as I know.
Local Storage, to store notes as text.
Google Translate text-to-speech.
Everything works, but in different browsers. The voice input works perfect, only in chrome. The text-to-speech works in safari.
To dynamically load the memo into the audio>source element i use:
$("#spokenmemory").html("<source src='http://translate.google.com/translate_tts?tl=en&q="+localStorage['memory']+"' />");
(the localStorage['memory'] contains my stored text memo)
To play my recently saved memo with googles text-to-speech-function I use:
$("#listenplay").click(function(){
$("#spokenmemory")[0].play();
});
(spokenmemory is the id-attribute of my audio-tag)
This does'nt work to play in chrome, but if I visit the translation link (example: http://translate.google.com/translate_tts?tl=en&q=Japan, and my text-memo is "Japan") in a separate browser-tab and then return to my site and reload the page (with the same text-memo "Japan" saved), the playback works. How strange, and annying!
Has anyone any idea of this strange behaviour?
It is because google restricts certain types of requests to prevent the service from being overloaded. So the audio file is not fetched when your browser tries to fetch it. Once you visit the translation link, the audio file is fetched and is cached which is why the playback works (provided the text-memo is same). This has been my observation but I'm not very sure.
When I used CURL to fetch the file, this is what I got in response:
403. That’s an error.Your client does not have permission to get URL /translate_tts?q=hello from this server.
I tried hard Gustav, and this is what I found after a bit of research and testing.
It seems Chrome is having trouble streaming mp3 (the format google returns). The only solution I can imagine is getting the file (cURL?) to your server and then present it to the user. I assume when Google releases the official API, there will also be some sort of a format option.
http://code.google.com/p/chromium/issues/detail?id=45152
http://www.trygve-lie.com/blog/entry/html_5_audio_element_and (yes, the play button is the same color as the background, funky)

Is there a convenient tool for viewing/analyzing JSON responses?

I find it inconvenient using my browser to view JSON responses, then copy/paste the code into my editor, then have to put line-breaks in to make it more readable.
It would be great to have a tool that allows me to enter a URL and receive a JSON in a more usable format, like say, a drill-down tree, or at least some color-coding of the text.
What tools are recommended?
When not using Firebug in Firefox, I've used JsonViewer and pasted in my JSON text.
Use the javascript developer window in Google Chrome. You can drill down into any objects.
Just type e.g. "JSON.parse(your_json_string)" and click away!