Android Question (Solved)WebView Post

iCAB

Well-Known Member
Licensed User
Longtime User
Hi Guys

I am looking for an example that shows how to invoke a login page in webview. The page requires POST and passing the user name and password in json format.

Thanks in advance
iCAB
 
Why use WebView for this? You should send POST requests with OkHttpUtils2.
Hi Erel,
The requirements are as follows:
  • we must load an existing web page in the browser
  • pass the user's email address
  • the user enters his password and clicks login
  • if login is successful, the page returns a security token as a cookie
  • we must capture the token for all future communications (which will be using OkHttpUtils)
That's why I was thinking that Webview is the way to go

Thanks
iCAB
 
Upvote 0
So, just get the cookie from Webview after login.
 
Upvote 0
use a formular and submit the formular. Formulars are send by POST
 
Upvote 0
Though I'm not using it any more (replaced such requests with okHttpUtils2), here's how I did it in the past:
Code: Copy
Private tempPostUrl As String="yourURL"
Private tempPostString As String="yourPostData after encoding URL"
Private bytesOfPOstRequest() As Byte
bytesOfPostRequest=tempPostString.GetBytes("UTF8")
Private jo As JavaObject=yourWebView
jo.RunMethod("postUrl",Array As Object(tempPostUrl,bytesOfPostRequest))
 
Upvote 0
Though I'm not using it any more (replaced such requests with okHttpUtils2), here's how I did it in the past:

Thanks a lot, sounds good I will give it a try.

One question with regards to the above. The code says "after encoding the URL"

Code: Copy
Private tempPostUrl As String="yourURL"
Private tempPostString As String="yourPostData after encoding URL"

I see that POST data being encoded
Code: Copy
Private bytesOfPOstRequest() As Byte
bytesOfPostRequest=tempPostString.GetBytes("UTF8")

At what point tempPostUrl is being encoded?

Thanks
iCAB
 
Upvote 0
Thanks a lot, sounds good I will give it a try.

One question with regards to the above. The code says "after encoding the URL"

Code: Copy
Private tempPostUrl As String="yourURL"
Private tempPostString As String="yourPostData after encoding URL"

I see that POST data being encoded
Code: Copy
Private bytesOfPOstRequest() As Byte
bytesOfPostRequest=tempPostString.GetBytes("UTF8")

At what point tempPostUrl is being encoded?

Thanks
iCAB

You have to use stringUtils (lib) for this:
Code: Copy
Private su As StringUtils
Private tempPostString as string=su.EncodeUrl(originalPostString,"UTF8")
 
Upvote 0
Back
Top