httputils

caillaud

Member
Licensed User
Longtime User
HI
thanks very much
the response of the server is:fromserverHELLOWORLD
Dim response As String
response=HttpUtils.getstring(ServerUrl)

1_)how can I read this response:
Msgbox(response, "hotelbynet")?
or
Log(response)?
2_)on the emulator there is a label control:label1
how can I send the response to this label1 control
the emulator does not seem linked the the code behind
label1.text is not accepted

in fact I first implemented my hotel reservation on smartphone application
on windows phone 7 with visual studio 2010 express for windows phone
so I am lost in vb4andriod
sincerely
michel
 
Upvote 0

caillaud

Member
Licensed User
Longtime User
httputlis

Hi again
in fact I got an error message due to the connexion to the server
Url ="http://localhost/testvb4android"
message=org.apache.http.conn.Httphostconnect exception refused
my server is a microsoft server under IIS and not apache!!!
is there a solution?
sincerely
michel
 
Upvote 0

caillaud

Member
Licensed User
Longtime User
I try two url
ServerUrl ="http://www.travelhotelonline.com/testvb4android
and
ServerUrl ="http://localhost/testvb4android"
this time nothing in to log area
is the sub below correct?

Sub JobDone(job As String)
If HttpUtils.issuccess(ServerUrl) Then
Dim response As String
response=HttpUtils.getstring(ServerUrl)
Log(response)
End If
HttpUtils.Complete = False
End Sub
if you try:
"http://www.travelhotelonline.com/testvb4android"
on a webbrowser you get:
fromserver:HELLOWORLD
thanks in advance
sincerely
michel
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
It works for me.

This is the code.

Process_Globals:
B4X:
Dim myurl As String 
myurl = "http://www.travelhotelonline.com/testvb4android"

JobDone:
B4X:
If HttpUtils.IsSuccess(myUrl) Then
Log(HttpUtils.GetString(myurl))
End If

I get the response and the Html document in response:

B4X:
LogCat connected to: emulator-5554
** Activity (main) Create, isFirst = true **
Starting Job: J1
** Activity (main) Resume **
** Service (httputilsservice) Create **
** Service (httputilsservice) Start **
http://www.travelhotelonline.com/testvb4android done
fromserver:HELLOWORLD

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
</title></head>
<body>
    <form name="form1" method="post" action="default.aspx" id="form1">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE2MTY2ODcyMjlkZOlhO/5ORzphxnlK0Id1xbBEAQ9k" />
    <div>
        </div>
    </form>
</body>
</html>

** Service (httputilsservice) Destroy **
 
Upvote 0

caillaud

Member
Licensed User
Longtime User
Hi
sorry to bother you
I get an error:
** Service (httputilsservice) Create **


** Service (httputilsservice) Start **


Error. Url=http://www.travelhotelonline.com/testvb4android Message=Method Not Allowed


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">



<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>

<title>405 - Le verbe HTTP utilis� pour acc�der � cette page n'est pas autoris�.</title>

<style type="text/css">

<!--

body{margin:0;font-size:.7em;font-family:Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;}

fieldset{padding:0 15px 10px 15px;}

h1{font-size:2.4em;margin:0;color:#FFF;}

h2{font-size:1.7em;margin:0;color:#CC0000;}

h3{font-size:1.2em;margin:10px 0 0 0;color:#000000;}

#header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:"trebuchet MS", Verdana, sans-serif;color:#FFF;

background-color:#555555;}

#content{margin:0 0 0 2%;position:relative;}

.content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;}

-->

</style>

</head>

<body>

<div id="header"><h1>Erreur de serveur</h1></div>

<div id="content">

<div class="content-container"><fieldset>

<h2>405 - Le verbe HTTP utilis� pour acc�der � cette page n'est pas autoris�.</h2>

<h3>La page que vous recherchez ne peut pas �tre affich�e, car une m�thode incorrecte (verbe HTTP) a �t� utilis�e pour y acc�der.</h3>

</fieldset></div>

</div>

</body>

</html>

** Service (httputilsservice) Destroy **

my PC is under vista

sincerely
michel
 
Upvote 0

caillaud

Member
Licensed User
Longtime User
Hi
thanks for your quick answer
what do mean by code tag?
all the project is in the attachments
if there problem of reading I send a new attachement
here all the main module (with comments):
'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim ServerUrl As String
ServerUrl ="http://www.travelhotelonline.com/testvb4android"
'ServerUrl ="http://localhost/testvb4android"
'Dim response As String
'http://www.b4x.com/forum/basic4android-getting-started-tutorials/13166-connect-android-ms-sql-server-tutorial.html#post74199
'http://www.b4x.com/forum/basic4android-getting-started-tutorials/9176-httputils-android-web-services-now-simple.html#post50919
'http://www.b4x.com/forum/basic4android-updates-questions/
End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
'Dim response As String=""
'Dim ServerUrl As String=""
'ServerUrl = "http://localhost/vb4android"
'Dim Httputils As
End Sub

Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
HttpUtils.CallbackActivity = "Main"
HttpUtils.CallbackJobDoneSub = "JobDone"
End If
HttpUtils.poststring("job1",ServerUrl,"hotelselect")
End Sub

Sub Activity_Resume
If HttpUtils.complete=True Then JobDone(HttpUtils.job)

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub JobDone(job As String)
If HttpUtils.issuccess(ServerUrl) Then
'Dim response As String
'response=HttpUtils.GetString(ServerUrl)
'Log(response)
Log(HttpUtils.GetString(ServerUrl))
End If
HttpUtils.Complete = False
End Sub
'-------------------------------
sincerely
michel
 
Upvote 0

caillaud

Member
Licensed User
Longtime User
Hi
thanks a lot
super
I get the answer from the server using download instead of poststring
Now what I would like to do is to send the answer of the server to the control label1 of the emulator
is it possible?
the emulator is all black
I launch the designer for having the emulor as I design it
and when I press F5 the emulator becomes all black


sincerely
michel
 
Upvote 0

caillaud

Member
Licensed User
Longtime User
Hi
thanks for your answer
I did that you recommand
but I get an error:
Compiling code. Error
Error parsing program.
Error description: Undeclared variable 'label1' is used before it was assigned any value.
Occurred on line: 47
label1.text=response
I see my design and the label1 control when I lounch the designer
It seems the emulator is not connected to the application
in the contrary:
There is an icon "hotelbynetbyandroid" in the application display of the emulator (I did not insert this icon!!!)
When I click this icon it seems I run the application:
I get the fromserverHELLOWORLD on the log of the application but the emulator is black

I miss something
sincerely
michel
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
Okay.

So you have added the Label to the Acitivity using the designer.

You will need to declare this in the code as well.
In the designer, you can go into Tools > Generate Members
Any views that you add to the activity will be here, and if you 'check' them and and click Generate Members, they will add the Declarations and Events automatically to the code. [For more information read the Beginners Guide]

Alternatively, you can declare label1 in the Globals sub as:

B4X:
Dim label1 as Label
 
Upvote 0

caillaud

Member
Licensed User
Longtime User
Hi
thanks very much
is the Beginners Guide online?
I add the controls with the designer
1)I get a java.lang.Runtimeexception:
object should be first initialized(label).
did you forget to call activity
loadlayout? continue?
2)in the label.text I get not only the fromserverHELLOWORLD but also
the httpp design of the page
I suppose it is to me to extract, by programmation, just the fromserverHELLOWORLD which only I need
3) VERY WORRYING:
I have to send to the server orders of the internaut:
hotel dates of stay etc..
if ServerUrl ="http://www.travelhotelonline.com/testvb4android"
is the basic URL
the only manner to send orders is:
for exemple
http://www.travelhotelonline.com/testvb4android?hotel=xxxx|mar12|mar14|"
but it is refused at the runtime
how can I send orders to the server?

very sincerely
michel
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
Hi
thanks very much
is the Beginners Guide online?
I add the controls with the designer
1)I get a java.lang.Runtimeexception:
object should be first initialized(label).
did you forget to call activity
loadlayout? continue?
2)in the label.text I get not only the fromserverHELLOWORLD but also
the httpp design of the page
I suppose it is to me to extract, by programmation, just the fromserverHELLOWORLD which only I need
3) VERY WORRYING:
I have to send to the server orders of the internaut:
hotel dates of stay etc..
if ServerUrl ="http://www.travelhotelonline.com/testvb4android"
is the basic URL
the only manner to send orders is:
for exemple
http://www.travelhotelonline.com/testvb4android?hotel=xxxx|mar12|mar14|"
but it is refused at the runtime
how can I send orders to the server?

very sincerely
michel

You havent read the beginners guide :eek::eek::eek:
Go here now: http://www.b4x.com/forum/basic4android-getting-started-tutorials/9578-beginners-guide.html

1) You havent called loadlayout. Read the beginners guide.

2) You will have to do this yourself.

3) Your server must accept POST requests.
 
Upvote 0

caillaud

Member
Licensed User
Longtime User
hi
thanks for your quick answers
1) You havent called loadlayout. Read the beginners guide:
fine: I get the response in label1

2) why I get an error just for that?:
compiling code. Error
Error compiling program.
Error description: Syntax error.
Occurred on line: 77
Dim fin As Int = response.IndexOf("<!DOCTYPE")
Word: int

I get the same error with
Dim myurl As String =ServerUrl+"?query=1holtelselect|1|"
word: string
sincerely
michel
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
2) why I get an error just for that?:
compiling code. Error
Error compiling program.
Error description: Syntax error.
Occurred on line: 77
Dim fin As Int = response.IndexOf("<!DOCTYPE")
Word: int
Try this:
B4X:
Dim fin As Int : fin = response.IndexOf("<!DOCTYPE")

I get the same error with
Dim myurl As String : ServerUrl+"?query=1holtelselect|1|"
word: string
sincerely
michel

Try this:
B4X:
Dim myurl As String  : myurl = ServerUrl & "?query=1holtelselect|1|"
 
Last edited:
Upvote 0

caillaud

Member
Licensed User
Longtime User
htpputils

Hi
thanks very much
everything works fine
-mysql=ServerUrl & "?query=1holtelselect|1|"
is accepted
so the server can receive the orders of the smartphone owner
-in label1 there is just it is needed

now I have to fill up a listview and react to a tap on a radiobutton
before asking help I am going to study these problems

just a question:
I need a lot of subs
I have to open a module for stocking them
project>add new module>>
do I open code a service module? or a code module?

sincerely
michel
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
just a question:
I need a lot of subs
I have to open a module for stocking them
project>add new module>>
do I open code a service module? or a code module?

Before you add a lot of subs, I suggest you refactor your code to make it generalised so you need as less subs as possible. This will help you in code maintenance and bug fixing.

If you require user interaction or display, add an activity module.
If you have general code or common reusable code use a code module.
I dont think you need a service module, but those are useful for background tasks, scheduling and many other things.
 
Upvote 0

caillaud

Member
Licensed User
Longtime User
HI
I have big problem for sending orders to the sever:
if I do that:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
'Dim myurl As String
myurl ="http://www.travelhotelonline.com/testvb4android?query=1hotelselect1"
End Sub
the order:1hotelselect1"
is sent to the server and the answer is fine
but if Ido that (and it is mandatory):
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim ServerUrl As String
ServerUrl ="http://www.travelhotelonline.com/testvb4android"
'Dim myurl As String
End Sub
then:
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("hotelbynet.bal")
If FirstTime Then
HttpUtils.CallbackActivity = "Main"
HttpUtils.CallbackJobDoneSub = "JobDone"
End If
myurl= ServerUrl & "?query=1holtelselect1"
HttpUtils.Download("job1", myurl)
End Sub
the order:"?query=1holtelselect1" is not sent to the server
just:
="http://www.travelhotelonline.com/testvb4android"
is sent to the server and the answer is not correct:
fromserverHELLOWORLD
at different sub of the application I have to send different orders to the server

thanks in advance
sincerely
michel
 
Upvote 0
Top