Android Question PostMultiPart error

rossati

Active Member
Licensed User
Longtime User
Hello
I report a problem arose with PostMutipart and as I worked around it.
I'm trying to send messages and photos to Telegram using PostMultipart of OkHTTPUtils2; this works for messages, but not for pictures (Unsupported media type).
I have bypassed the obstacle using a forwarder site where a PHP script use CURL library for send Message and pictures to Telegram; this works if I have message and pictures, fails when there is only a message
(illegal characters found in URL).
This is because the last parmeters on parameters map is sent with x0D0A.
Adding a dummy field sending was successful.
B4X:
... 
parameters.Put("x","y")        ' without this is unable to send only message
    job1.Initialize("Job1", Me)
    job1.PostMultipart("http://www.condorinformatique.com/Telegram/ToTelegram.php",parameters,files)
...
PHP has received: x790d0a

John Rossati
 

DonManfred

Expert
Licensed User
Longtime User
you can pass null for the parameters if you dont need them
 
Upvote 0

rossati

Active Member
Licensed User
Longtime User
Yes, I know but it si not the problem, I am passing some parameters and the last is affected by Carriage return and Line Feed.
 
Upvote 0

rossati

Active Member
Licensed User
Longtime User
The parameters are chat_id, Message and bot; only message contanis LineFeed, but do not bother, as it is sent.
Talking to you I clarified the behavior: because the last parameter is the bot and it is parte of the site:
and bot having CR/LF at end produces (illegal characters found in URL).
So, I think, it is a PostMultiPart error.
 
Upvote 0

rossati

Active Member
Licensed User
Longtime User
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Dim job As HttpJob
    job.Initialize("Job1",Me)
    job.Download2("http://donmanfred.basic4android.de/test1.php",Array As String("a","Aa","b","Bb"))
End Sub

Sub JobDone (Job As HttpJob)
    Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
    If Job.Success = True Then
        Select Job.JobName
            Case "Job1"
                'print the result to the logs
                Log(Job.GetString)
        End Select
    Else
        Log("Error: " & Job.ErrorMessage)
        ToastMessageShow("Error: " & Job.ErrorMessage, True)
    End If
    Job.Release
End Sub

The called PHP is THIS:
PHP:
<?php
  foreach ($_GET as $key => $value){
    echo "$key = $value\t hex: ".bin2hex($value)."\r\n";
}
echo "a = ".$_GET["a"]."\t hex: ".bin2hex($_GET["a"])."\r\n";
echo "b = ".$_GET["b"]."\t hex: ".bin2hex($_GET["b"])."\r\n";
?>


** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (httputils2service) Create **
** Service (httputils2service) Start **
JobName = Job1, Success = true
a = Aa hex: 4161
b = Bb hex: 4262
a = Aa hex: 4161
b = Bb hex: 4262
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **

Edit: Sorry... Did not used PostMultipart....

I did try now and i run into an error when using job.PostMultipart... I´m investigating... Something is wrong with my setup.

Stay tuned; i´ll answer later agin
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
You are right... It happens here also

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Dim j As HttpJob
    j.Initialize("Job1",Me)
    Dim m As Map
    m.Initialize
    m.Put("a","Aa")
    m.Put("b","Bb")
    Dim l As List
    l.Initialize
    j.PostMultipart("http://donmanfred.basic4android.de/test1.php",m,l)
End Sub

Sub JobDone (Job As HttpJob)
    Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
    If Job.Success = True Then
        Select Job.JobName
            Case "Job1"
                'print the result to the logs
                Log(Job.GetString)
        End Select
    Else
        Log("Error: " & Job.ErrorMessage)
        ToastMessageShow("Error: " & Job.ErrorMessage, True)
    End If
    Job.Release
End Sub

The PHP is looking for $_POST for sure...

PHP:
<?php
  foreach ($_POST as $key => $value){
    echo "$key = $value\t hex: ".bin2hex($value)."\r\n";
}
echo "a = ".$_POST["a"]."\t hex: ".bin2hex($_POST["a"])."\r\n";
echo "b = ".$_POST["b"]."\t hex: ".bin2hex($_POST["b"])."\r\n";
?>
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (httputils2service) Create **
** Service (httputils2service) Start **
JobName = Job1, Success = true
a = Aa hex: 4161
b = Bb
hex: 42620d0a
a = Aa hex: 4161
b = Bb
hex: 42620d0a
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **

The last parameter get´s an CRLF added.
 
Upvote 0
Top