How to post request using httputils2

gordon

Member
Licensed User
Longtime User
How do I postbytes using httputils2 please. I have been stepping through the flicker tut and adapting it to learn from it but am stuck. I want to do a post request.

The Link has been formed into a bona fide url . The Text as string has been processed through Text.Bytes("UTF8") All this has been passed to

B4X:
Public Sub PostBytes(Link As String, Data() As Byte)
   mLink = Link
   
   req.InitializePost2(Link, Data)
   
   CallSubDelayed2(HttpUtils2Service, "SubmitJob", req)
End Sub

Now when I go to amend

B4X:
Public Sub SubmitJob(job As HttpJob) As Int



End Sub

I am stuck. Instead of

B4X:
hc.Execute(job.GetRequest, taskCounter)

I want to

B4X:
hc.Execute(job.PostBytes

As far as I can tell job.PostBytes wants a Link as a string and Data as a byte array. But these have not been passed to the sub SubmitJob. Please Help. Many thanks.
 

gordon

Member
Licensed User
Longtime User
Well I've sort of got it. I understand now that the url and the text data are wrapped in the req wrapper and that is passed to the sub SubmitJob as an http request.

If I hard code everything into the url it all gets posted and the result string is as expected.

But. If I try and send it as url and text data that is

B4X:
url ="http://www.myserver/Process/prequest.php?"

and the text data =
B4X:
"&moc[name]=" & name & "&moc[finaltime]=" & finaltime & "&moc[finaldate]=" & finaldate  )
then for some reason nothing gets put to the dbase and the result string is empty, that is no error code or message of any sort.

If anyone could help be grateful.
 
Upvote 0

gordon

Member
Licensed User
Longtime User
Well I need to alter something, because in the given example, flkr, the sub SubmitJob seems only to be executing get jobs and I am trying to learn how to use httpsutils2 to execute post jobs, but so far to frustratingly little effect, but what it is I need to change or add remains a mystery.
 
Upvote 0

coley

Member
Licensed User
Longtime User
How do I POST a url but not pass any data?

Both PostBytes and PostString need additional data and the webserver I need to communicate with will not accept this.

for example my post url is as follows:-

B4X:
http://192.168.0.19:4590/Web/action?q=RaiseCustomEvent(CustomEventId(5001),3b8a80386b7d4a58841bcaad3fcb56ff

I have no issues connecting with other devices such as PC or PIC Microcontroller and an example of a successful raw HHTP stream is as follows:-
B4X:
POST /Web/action?q=RaiseCustomEvent(CustomEventId(5001),3b8a80386b7d4a58841bcaad3fcb56ff) HTTP/1.1
Content-Type: application/xml
Host: 192.168.0.19:4590
Content-Length: 0
Connection: Close

The same web service also has GET requests and that part is working just great with the following example.

B4X:
job1.Initialize("Job1", Me)
job1.Username = "User1;KxsD11z743Hf5Gq9mv3+5ekxzemlCiUXkTFY5ba1NOGcLCmGstt2n0zYE9NsNimv"
job1.Password = "123456"
job1.PostString("http://192.168.0.19:4590/Web/activealarms")

Any help will be greatly appreciated.

Regards,

Coley
 
Upvote 0

coley

Member
Licensed User
Longtime User
Never mind, I got it working with this....


Pretty obvious really lol :sign0104:
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…