HTTP Post still driving me crazy!!!

lagore

Active Member
Licensed User
Longtime User
I have finally got my device accessing the web but it is not doing what I am expecting. The following is a very basic test program to log into gmail just put your username and password in the relevant text boxes and press GO. It should either log in successfully and show the new gmail logged in screen in the webview or else the 'have you entered the correct username/password' screen, but in just shows the first screen before you login.

B4X:
Sub Process_Globals
   Dim postData As String
   Dim PostUrl As String

End Sub

Sub Globals
   
   Dim GoBtn As Button

   
   Dim s As String
   
   Dim WebView1 As WebView
   Dim PasswordTxt As EditText
   Dim UserNameTxt As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
    
   Activity.LoadLayout("layout1")

End Sub


Sub GoBtn_Click

   postdate = "ltmpl=default&ltmplcache=2&pstMsg=1&dnConn=https%3A%2F%2Faccounts.youtube.com&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F%3F&service=mail&rm=false&dsh=5677402227554726706&ltmpl=default&ltmpl=default&scc=1&timeStmp=&secTok=&GALX=JwTvGlScxBM&Email=" & UserNameTxt.Text  & "&Passwd=" & PasswordTxt.Text & "&rmShown=1&signIn=Sign+in&asts="
   PostUrl = "https://www.google.com/accounts/ServiceLoginAuth"
   


   HttpUtils.CallbackActivity = "Main"
   HttpUtils.CallbackJobDoneSub = "JobDone"
   HttpUtils.CallbackUrlDoneSub = "UrlDone"
   Msgbox("Sending URL","")

   HttpUtils.PostString ("Job1",PostUrl,postData)

   
   
End Sub


Sub UrlDone(Url As String)
   Log(Url & " done")
   
End Sub

Sub JobDone (Job As String)
   
   Msgbox("Getting return","")
   If HttpUtils.IsSuccess(postUrl) Then
      s = HttpUtils.GetString (postUrl)
      
      WebView1.LoadHtml(s)
   End If
End Sub

What am I doing wrong? (before I have no hair left)
Thanks
Edward
 

lagore

Active Member
Licensed User
Longtime User
I am getting the data using fire bug, I know the data is correct as it is the same that I use in a VB program,in fact it does not matter what is used in the gmail login program even if nothing is used as the POST should generate a return from the server which will be like the attached jpg. The return I get is like the login screen before you attempted to login which it should not be.
Edward
 

Attachments

  • gmail incorrect login.jpg
    gmail incorrect login.jpg
    15 KB · Views: 251
Upvote 0

GeordieJenner

Member
Licensed User
Longtime User
this makes me thing... the one of the reasons i hate concatenated strings for variables,
if strData="Tom & Jerry"
how will the postURL handle the ampersand?
"https://www.abc.com/service1.svc?strName=" & strData & "&Address=123 Maple"
 
Upvote 0

kanaida

Active Member
Licensed User
Longtime User
Try StringUtils URL encode those values. Those definately won't like getting special symbols that aren't converted to their html/url values like %3D etc...

Since you are already doing the url string, most likely properly, just encode those values. Try it out.
 
Upvote 0

lagore

Active Member
Licensed User
Longtime User
POST and GET appear the same

I have been experimenting with the HTTP POST and GET and I believe that the POST is in fact doing a GET as it just returns the website contained in post URL. So same data is returned with either;
req.InitializePost2 (PostUrl,postdata.GetBytes("UTF8"))
req.InitializeGet(PostUrl)
Even if the postdata was not correct the POST should return a modified site stating that invalid data/username/password was entered.
Has anybody managed to do a successful HTTP POST to a site particularly to a login like gmail.
Edward
 
Upvote 0

lagore

Active Member
Licensed User
Longtime User
I currently sent the content type to
req.SetContentType("application/x-www-form-urlencoded")
this should indicate to the server side that the information is contained within the postdata.
How or what additional info do I need to set in Headers to complete the request. When I program the POST in VB.net I also set the UserAgent eg,
postReq.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.11) Gecko/20101012 Firefox/3.6.11 GTB7.1 ( .NET CLR 3.5.30729)"
not sure if this needs to be done here and how?
Edward
 
Upvote 0

boastrike

Member
Licensed User
Longtime User
I know this is an older thread but a good example of how the coloring in the editor helps! The word "postdate" shows up in bright red giving that hint that it should have been "postdata". I wonder if that would have saved some hair...? :)

B4X:
postdate = "ltmpl=default&ltmplcache=2&pstMsg=1&dnConn=https%3A%2F%2Faccounts.youtube.com&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F%3F&service=mail&rm=false&dsh=5677402227554726706&ltmpl=default&ltmpl=default&scc=1&timeStmp=&secTok=&GALX=JwTvGlScxBM&Email=" & UserNameTxt.Text  & "&Passwd=" & PasswordTxt.Text & "&rmShown=1&signIn=Sign+in&asts="
    PostUrl = "https://www.google.com/accounts/ServiceLoginAuth"
    


    HttpUtils.CallbackActivity = "Main"
    HttpUtils.CallbackJobDoneSub = "JobDone"
    HttpUtils.CallbackUrlDoneSub = "UrlDone"
    Msgbox("Sending URL","")

    HttpUtils.PostString("Job1",PostUrl,postData)
 
Upvote 0

lagore

Active Member
Licensed User
Longtime User
Its a bit late for the hair now but you are absolutely correct, now how come I did not notice that at the time!!!:signOops:
 
Upvote 0
Top