Hi
I am currently converting a program which I have written in VB.net to run on Android using Basic4Android but I am not having any success with the POST method.
The bit of code in VB.net that works is,
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
My code in Basic4Android is
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
When I run the code I get the following error
Any ideas what I need to change or am I trying to do something that either Android or Basic4Android cannot do. The long timeout is required as the site can be slow to respond.
Am I correct in stating that the Android OS takes care of cookies in the background so that is one aspect I do not have to worry about.
Unfortunately neither bits of code will not work if you paste them into the IDE as I have changed/removed any sensitive information.
Edward
			
			I am currently converting a program which I have written in VB.net to run on Android using Basic4Android but I am not having any success with the POST method.
The bit of code in VB.net that works is,
			
				B4X:
			
		
		
		Dim postData As String = "username=myusername&password=mypassword&back=https%3A%2F%2Fecrew.mysite.com%2Fwtouch%2Fwtouch.exe%2Findex%3FMAC%3D0%26VER%3D0"
        Dim tempCookies As New CookieContainer
        Dim encoding As New UTF8Encoding
        Dim byteData As Byte() = encoding.GetBytes(postData)
        Dim postReq As HttpWebRequest = DirectCast(WebRequest.Create("https://portal.mysite.com/weblogin/bin/weblogin.cgi"), HttpWebRequest)
        postReq.Method = "POST"
        postReq.KeepAlive = True
        postReq.CookieContainer = tempCookies
        postReq.ContentType = "application/x-www-form-urlencoded"
        postReq.Referer = "https://portal.mysite.com/weblogin/bin/weblogin.cgi"
        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)"
        postReq.ContentLength = byteData.Length
        Dim postreqstream As Stream
        Try
            postreqstream = postReq.GetRequestStream()
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error Logging on to the mysite Portal")
            Error_Writer("mysite Portal Initial Login" & vbCrLf _
                         & ex.Message & vbCrLf)
            Return
        End Try
        postreqstream.Write(byteData, 0, byteData.Length)
        postreqstream.Close()
        Dim postresponse As HttpWebResponse
        postresponse = DirectCast(postReq.GetResponse(), HttpWebResponse)My code in Basic4Android is
			
				B4X:
			
		
		
		Sub Process_Globals
          Dim hc As HttpClient
End Sub
Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
        hc.Initialize("hc")
      End If
   
   postData = "username=myusername&password=mypassword&back=https%3A%2F%2Fecrew.mysite.com%2Fwtouch%2Fwtouch.exe%2Findex%3FMAC%3D0%26VER%3D0"
   PostUrl = "https://portal.mysite.com/weblogin/bin/weblogin.cgi"
   Dim str() As Byte
   
   str = postData.GetBytes("UTF8")
   
       Dim req As HttpRequest
   req.InitializePost2(PostUrl, str)
   req.SetContentType("application/x-www-form-urlencoded")
   req.SetContentEncoding("UTF8Encoding")
   req.Timeout=45000
 
       hc.Execute(req, 1)
End subWhen I run the code I get the following error
Error. Url=https://portal.mysite.com/weblogin/bin/weblogin.cgi Message=java.net.UnknownHostException: portal.mysite.com
Any ideas what I need to change or am I trying to do something that either Android or Basic4Android cannot do. The long timeout is required as the site can be slow to respond.
Am I correct in stating that the Android OS takes care of cookies in the background so that is one aspect I do not have to worry about.
Unfortunately neither bits of code will not work if you paste them into the IDE as I have changed/removed any sensitive information.
Edward
 
				 
 
		 
 
		 
 
		 
 
		 
 
		