Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: httpConnection can´t send query, difficulties with setRequestProperty

If you send a request to a web server, the response that it sends back will reflect what you send it. So you need to send a correctly formatted request to get the response you want. 

 

I have not tried to use Google in the way you are, but I think the documentation you need for using Google search is here:

https://developers.google.com/custom-search/v1/overview

 

As you will see, this is not a trivial exercise.  If you need help with this, you will need to get help from other forums. 

 

At present you are not using this API, so as far as Google is concerned, you are just a Browser.  When a Browser makes a request, it expects that data that comes back will be HTML.  This is a specified mark up language, you will find a number of places that document this.  The Browser takes the HTML and decides how to render this on the device.  Typically the HTML includes formatting instructions (like font specifications) as well as links to other resources and so on.  HTML is language in its own right really. 

 

Anyway, what you have proved is that the BlackBerry can get data from a web server.  If you want your program to sign in to your home server, then you are going to have to do what I suggested in my last post, i.e. reverse engineer the HTML pages that the Server sends to you, and simulate these on the BlackBerry.  This is not a trivial exercise either, you will need to learn to read HTML.  And you will need to use GET or POST as the Web Server expects,  And your Java program will be pretending to be a Browser, so will get the full HTML pages which it might have to search through. 

 

It might be better to focus on the connection issue you were originally having.  In fact I would suggest it is better to. 

 

Finally a quick code review.

 

1) If you use GET, do not include POST data, it is ignored.  The only data that is relevant is on the query (which you code as part of the httpURL).

2) I am not sure you have got the hang of headers.  On the request you send in, you set them.  if you don't set them, they don't exist.  There is no point trying to find out what they are using code like this:

String contentType_1 = httpConn.getHeaderField("WWW-Authenticate");

.3) On the response you get back, you can interrogate the response headers.  I think it is essential that you do this.  I strongly encourage you to put the debugging code I have given you to do this, in your code. 

Contributor
bb_eibl
Posts: 26
Registered: ‎04-09-2013
My Device: not specified

Re: httpConnection can´t send query, difficulties with setRequestProperty

Yes I could read from all servers ever since, also from the server I originally was working with, this was not a problem, as you might see in what I wrote at the beginning o fthe thread. It was only possible with the GET method!!

 

The problem is to send the right query and extract the relevant information from the reply.

 

In the rudimentary documentation of my target server it is written , that commands like

 

Setting values

<form action="./thispage.htm" method="GET">

<input type="submit" value=" 1 " name="SM1-1">

 

have to used to set variables and

 

Reading values:

objects can be displayed on HTML pages by using PHP instructions.

PHP is a hypertext preprocessor, which analyzes the HTML file before it is sent to the browser. PHP instructions

instructions are evaluated at the time the file is sent to the browser, but the instructions are taken out of the HTML code.Instead PHP instructions can modify the HTML code which is generated at the time the file is transferred.

With this concept, current values of communication objects can be displayed on a browser surface.

 

The PHP implementation has the following predefined variables:

Communication object values: $A1value, $A2value, $A3value, $A4value, $B1value .. $Z4value

A PHP variable is always prefixed by a „$“ sign. It is followed by the already described object number (A1..Z4)

 

I think: The server wil send HTML code which I need to be able to read.

 

In SUMMARY: I think 1) I can forget about POST and just use GET. 2) I have to be able to deal with HTML and be able to read it. Do you agree ?

 

 

I will come to your point in an additional post, I have it on my list, it is not forgotten !

It might be better to focus on the connection issue you were originally having.  In fact I would suggest it is better to.

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: httpConnection can´t send query, difficulties with setRequestProperty

PHP is a server side language used to process HTTP protocol requests and format HTML pages in return.  You can't run PHP on the BlackBerry.  On the Server, it parses the HTTP input request and extracts the past in variables so that the person writing the PHP has an easier job.  But this does not help you on the BlackBerry. 

 

This:

<form action="./thispage.htm" method="GET">

<input type="submit" value=" 1 " name="SM1-1">

would suggest that you construct an HTML GET URL along the lines of:

http://<your server>/thispage.htm?SM!-1=1

but I am not HTML expert - this is just a guess.  For help in converting this to a GET request you will have to look elsewhere (in another forum, since this is 'conversion' not BlackBerry related). 

 

"In SUMMARY: I think 1) I can forget about POST and just use GET. 2) I have to be able to deal with HTML and be able to read it. Do you agree ?"

 

1) I don't know.  I can see form the above that it looks like the Server will accept GETs, but that might be just one SUBMIT, others might use POST. 

 

2) Yes, unless you can find some documentation regarding your Server that provides a different response.  As it stands, your code will be provided HTML pages because your code is pretending to be a Browser. 

Contributor
bb_eibl
Posts: 26
Registered: ‎04-09-2013
My Device: not specified

Re: httpConnection can´t send query, difficulties with setRequestProperty

Thank´s very much for your  help and advise, I really appreciate, also your patience !! It is not an easy job you are doing. I will contact you when I have something new, it will take some time though.

Contributor
bb_eibl
Posts: 26
Registered: ‎04-09-2013
My Device: not specified

Re: httpConnection can´t send query, difficulties with setRequestProperty

I got back to the message you sent to me in which you added code and you wanted me to implement it.

 

I will just explain where I am, I moved forward significantly. After reading this, please tell me whether you still believe that I should implement the code.

 

Just a brief outine: I want to connect to a server and read data and process them further. The pages of the server are in html and javascripts are also there.

 

 

 

1) I tried to use httpConnection, I  sent requests,but  I could net get any answer on my queries and I gave this line up

2) I tried to use the BrowserField2, I always got error 401, I gave this line up

3) I used httpConnection, downloaded the html page from the server by reading bytes, saved the html file on the simulator and loaded this page into the browser. THIS WORKED. Certainly this cannot stay like this, but it is a first succes.

4) with method 3 I can only read pure text pages, the download and file saving of the page will always work but the BrowserField cannot display the content if it is not plain text.

 

There is a huge number of  settings of the BrowserFieldConfig. I would like to know how do I have to set these values to make the Browserfield work and read the html files of  the server, even if they contain variables and graphics.

 

A second problem is the real device and the standard blackberry browser. There, no connection to my server is possible at all, user authentication fails, I always get error 401. With my small program that I wrote I can read pages of my server that I cannot read with the commercial BlackBerry browser.

 

Summary: (i) I do not think I can learn from reading the headers at this stage, the code you recommended me to use. Could you explain which headers I can read and why you believe that this si important (ii) I would like to know how to configure the browserField properly such that it can read HTML including variables plus graphic, (iii) how do I have to configer the browser  the real device that it can connect to the server.

 

 

 

I also realized that the browserField can´t open html pages of my server which I saved with FIREFOX. FIREFOX and any other server can. Could you explain why and how to overcome this.

 

Please give me feed back on this e-mail, even if you do not want to comment on the subject further. Thank´s !!:smileyhappy:

 

 

 

 

 

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: httpConnection can´t send query, difficulties with setRequestProperty

[ Edited ]

Can you please tell us what device you are trying this from, what carrier you are using and whether you have a full data plan.

 

From my understanding, the issue that started this whole saga was the fact that the Browser had some problems communicating with your home server.  I would like to understand this before we investigate any other options. 

 

Can you confirm that the Browser will display other pages correctly. 

 

Edit: 

 

I forgot to answer some of your other queries:

i) The headers will demonstrate which server you are actually communicating with.  This is useful diagnostic information.  For example, if  you get back a 401, then it is useful to know which Server is actually requesting authentication.  It might not be your home server but could be a gateway in between. 

I) There should be no configuration needed in most cases

iii) That is the path I would like to investigate first. 

 

I will leave the Firefox saved pages till later.  But have you tried to open a Firefox saved page using IE? 

 

Finally I do not provide support by email sorry, except of course to paying clients.....

Contributor
bb_eibl
Posts: 26
Registered: ‎04-09-2013
My Device: not specified

Re: httpConnection can´t send query, difficulties with setRequestProperty

I tried  to access the site with the browser of the simulator and the browser of the real device (torch 9800) both ways are not working, error 401.

 

 

In the same network I have several PCs with IE and Firefox work, no problem with  this browser. Android smartphones and Android tablets don´t have any problem with this server, they are all linked in the same network. It is a browser problem of the  BB browser. the download of the files (HTML Pages of the server) via a http connection  does work and the files look ok.

 

This was the answer to your questions.

 

It would be nice if you could answer my questions as well: I need a smart solution how to display a byte array, that contains HTML code, by the browser without saving the byte array to a  file and then display the file in the browser.

 

The browser has difficulties with dynamic content, I believe  it can only display static content, why ??

 

Thank´s

 

 

 

 

 

 

Contributor
bb_eibl
Posts: 26
Registered: ‎04-09-2013
My Device: not specified

Re: httpConnection can´t send query, difficulties with setRequestProperty

I insert my answers by ">>"

 

Can you please tell us what device you are trying this from, what carrier you are using and whether you have a full data plan.

 

>> BB torch9800, carrier Vodafone, "full data plan" I don´t know what this is.

 

From my understanding, the issue that started this whole saga was the fact that the Browser had some problems communicating with your home server.  I would like to understand this before we investigate any other options. 

 

>>correct, problem 401, authentication required.

 

Can you confirm that the Browser will display other pages correctly.

 

>> Yes it does. only pages that require authentication have problems.

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: httpConnection can´t send query, difficulties with setRequestProperty

"It would be nice if you could answer my questions as well:"

 

I try.  I don't know everything, for example with respect to BrowserFields but I answer what I can.  Believe me.  However I am concerned regarding a number of things and because I can't see what you are doing, I need to ensure my assumptions are correct.  So I tread cautiously. 

 

If you have a specific question that you really want me to answer, please highlight it. 

 

Can you please, using Manage Connections, turn off everything except WiFi on the phone.  Now try you Server IP address in the Browser and tell me what happens. 

 

 

Contributor
bb_eibl
Posts: 26
Registered: ‎04-09-2013
My Device: not specified

Re: httpConnection can´t send query, difficulties with setRequestProperty

i switched off everything but Wifi, I get error 401 as usual.

 

I do not think that we should proceed on this. I spent hours on that issue already. The combination of the built in browser and this server does not work. I have another server at home also with authentication for this the application  works, but it is file download not a browser application.

 

The Opera Browser that I have installed also on the phone, does not work either.

 

My summary: it is definitely the browsers that are not working properly.I spent already tens of hours on that problem but it alwys error 401 that I get. I changed the browser settings in various ways and it did not work. I can´t even get to the static text page.

 

If you don´t mind I would like to move to the programs, that I programmed and that are able to connect to the server:

 

************************* Question ******************************************

Is there a simple solution to get the HTML data  displayed that I dowloaded into a byte field, (wiithout saving them to a file) and then displaying the file in the browser ? It means displaying the byte data directly wit h the assistance of the browser.

******************************************************************************

 

Thank´s. :smileyhappy: