ilan Expert Licensed User Longtime User Feb 20, 2021 #1 hi, i am trying to send from my b4a app strings to a JRDC server. how do i get the content back in the RDCHandler - Handle event? this is my POST send code: B4X: Dim j As HttpJob j.Initialize("dbrequest",Me) j.Tag = "job1" j.PostString(rdcLink & "?method=" & method ,"abc") Handle event: B4X: Sub Handle(req As ServletRequest, resp As ServletResponse) '???? End Sub thanx Last edited: Feb 20, 2021
hi, i am trying to send from my b4a app strings to a JRDC server. how do i get the content back in the RDCHandler - Handle event? this is my POST send code: B4X: Dim j As HttpJob j.Initialize("dbrequest",Me) j.Tag = "job1" j.PostString(rdcLink & "?method=" & method ,"abc") Handle event: B4X: Sub Handle(req As ServletRequest, resp As ServletResponse) '???? End Sub thanx
Erel B4X founder Staff member Licensed User Longtime User Feb 21, 2021 #2 RDCHandler already reads the POST payload. See its code. It also seems like you are not using Wait For to get the result. This is a mistake. Upvote 0
RDCHandler already reads the POST payload. See its code. It also seems like you are not using Wait For to get the result. This is a mistake.
ilan Expert Licensed User Longtime User Feb 21, 2021 #3 thank you erel for your answer. so the post request should look like this: B4X: Dim j As HttpJob j.Initialize("dbrequest",Me) j.Tag = "job1" j.PostString(rdcLink & "?method=" & method ,"abc") Wait For(j) JobDone(j As HttpJob) If j.Success Then Log("Inserted successfully!") End If j.Release but i didnot understood you answer: Erel said: RDCHandler already reads the POST payload. See its code. Click to expand... do you mean from the req.InputStream ? thank you Upvote 0
thank you erel for your answer. so the post request should look like this: B4X: Dim j As HttpJob j.Initialize("dbrequest",Me) j.Tag = "job1" j.PostString(rdcLink & "?method=" & method ,"abc") Wait For(j) JobDone(j As HttpJob) If j.Success Then Log("Inserted successfully!") End If j.Release but i didnot understood you answer: Erel said: RDCHandler already reads the POST payload. See its code. Click to expand... do you mean from the req.InputStream ? thank you
Erel B4X founder Staff member Licensed User Longtime User Feb 21, 2021 #4 ilan said: do you mean from the req.InputStream ? Click to expand... Yes. Upvote 0
ilan Expert Licensed User Longtime User Feb 21, 2021 #5 Erel said: Yes. Click to expand... thanx erel, so i managed already to convert a map to byte send it with *.postbyte() and convert it back to a map from the req. InputStream. but if i send a string i have read somewhere that http already converts it to a byte object so i tought converting it back to string but i am getting an error. i solved it using a different approach. i append the string to the post url instead and then i am able to get the string back. is this the right way to do? B4X: Dim s As String = "abc" j.PostString(rdcLink & "?method=" & method & $"& data=${s}"$,"") thanx Upvote 0
Erel said: Yes. Click to expand... thanx erel, so i managed already to convert a map to byte send it with *.postbyte() and convert it back to a map from the req. InputStream. but if i send a string i have read somewhere that http already converts it to a byte object so i tought converting it back to string but i am getting an error. i solved it using a different approach. i append the string to the post url instead and then i am able to get the string back. is this the right way to do? B4X: Dim s As String = "abc" j.PostString(rdcLink & "?method=" & method & $"& data=${s}"$,"") thanx
Erel B4X founder Staff member Licensed User Longtime User Feb 21, 2021 #6 req.InputStream will work with PostString. You just need to add BytesToString to convert the array of bytes to a string. Use UTF8 encoding. Upvote 0
req.InputStream will work with PostString. You just need to add BytesToString to convert the array of bytes to a string. Use UTF8 encoding.
ilan Expert Licensed User Longtime User Feb 21, 2021 #7 Erel said: req.InputStream will work with PostString. You just need to add BytesToString to convert the array of bytes to a string. Use UTF8 encoding. Click to expand... ok thank you, i will try and if i get an error i will post the exact error + example project here. thanx Upvote 0
Erel said: req.InputStream will work with PostString. You just need to add BytesToString to convert the array of bytes to a string. Use UTF8 encoding. Click to expand... ok thank you, i will try and if i get an error i will post the exact error + example project here. thanx
ilan Expert Licensed User Longtime User Feb 21, 2021 #8 you were right erel. thank you for your support relevant code (if someone may need): B4X: Dim buffer() As Byte = Bit.InputStreamToBytes(in) Dim s As String = BytesToString(buffer, 0, buffer.Length, "UTF-8") Log(s) Upvote 0
you were right erel. thank you for your support relevant code (if someone may need): B4X: Dim buffer() As Byte = Bit.InputStreamToBytes(in) Dim s As String = BytesToString(buffer, 0, buffer.Length, "UTF-8") Log(s)