Android Question Strange Multipart request failure

jazzzzzzz

Active Member
Licensed User
Longtime User
I have to upload a image file to a server,I have used okhttp multipart upload request to send the request,I have tested the upload in lan using php server and it works perfectly in lan.

But when the php code is hosted in web it does not work.It gives this error in the app

B4X:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>501 Method Not Implemented</title>
</head><body>
<h1>Method Not Implemented</h1>
<p>GET to /photo_admin/mobile_api.php not supported.<br />
</p>
<p>Additionally, a 501 Method Not Implemented
error was encountered while trying to use an ErrorDocument to handle the request.</p>
</body></html>
Method Not Implemented

So I thought there is some server configuration issue and tested the same request using postman in my laptop and the file was uploaded perfectly..I Am totally confused why this is not working in App in web (but works on lan)

B4X:
<p>GET to /photo_admin/mobile_api.php not supported.<br />

But this line here shows its a get request..but multipartpost is a post request Why this happens...!

Any idea or suggestions>?
 

jazzzzzzz

Active Member
Licensed User
Longtime User
HttpJob.PostMultipart creates a POST request.

Seems like a server misconfiguration. Maybe the redirect table converts the POST request to a GET request.

But its working good in postman,If its a server configuration issue then post man should also fail right?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Can you post the code which sends the request?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
es. However PostMultipart creates a POST request. It will never create a GET request.
I´m sure you are right.

BUT (i may be wrong)

Assuming the following code

B4X:
    Dim files As List
    files.Initialize
   
    Dim fd As MultipartFileData
    fd.Initialize
    fd.KeyName = "pdf"
    fd.Dir = File.DirAssets
    fd.FileName = "schadensanzeige.pdf"
    fd.ContentType = "application/pdf"
    files.Add(fd)

    Dim job As HttpJob
    job.Initialize("Upload",Me)
    job.PostMultipart("http://basic4android.de/?varA=16",CreateMap("action":"panne","knr":7,files)

This IS is Post-Request.

But the value varA is given via GET and "action" and "knr" is given inside the post-payload as POST values.

Or i am wrong with this?
 
Upvote 0

jazzzzzzz

Active Member
Licensed User
Longtime User
Can you post the code which sends the request?

B4X:
Log("upload_pic")
    Dim j As HttpJob
    j.Initialize("upload_pic", Me)
    Dim fd As MultipartFileData
    fd.Initialize
    fd.KeyName = "upload_photo"
    fd.Dir = File.DirDefaultExternal
    fd.FileName = "1.jpg"
    fd.ContentType = "image/png"

    j.PostMultipart(Main.parentURL, CreateMap("action":"upload","access_token":Main.accessToken _
    ,"contest_id":Main.currentContestId,"user_id": Main.userID,"caption":desc.Text), Array(fd))
 
Upvote 0

jazzzzzzz

Active Member
Licensed User
Longtime User
Please check the text files I have uploaded.

One is data from emulator (This one does not works),And the other one is from postman(This one works).
Both data fetched by wireshark,I think the data looks same ..
 

Attachments

  • Wireshark - emulator.txt
    19.5 KB · Views: 225
  • Wireshark - Postman.txt
    404.1 KB · Views: 207
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
But the value varA is given via GET and "action" and "knr" is given inside the post-payload as POST values.

Or i am wrong with this?
You are correct that the parameters are GET parameters. However the request itself is a POST request.

@jazzzzzzz based on the wireshark logs we can see that it is actually a POST request. The server error message is wrong.

Where did the cookie value come from?
 
Upvote 0

jazzzzzzz

Active Member
Licensed User
Longtime User
I did lot of testing today..

I think its some issue related to our upload because I have test it with native iOS test app and uploading is working good.
So browser and native iOS upload is working good.I haven't test native java android

Please check this sample B4A project for testing upload http://arunneeraj.com/uploads/upload_test_b4a.zip

Given below is the server code.

B4X:
<?php

$imgName=$_FILES["file"]["name"];
move_uploaded_file($_FILES["file"]["tmp_name"],"uploads/" . $_FILES["file"]["name"]);
   
echo "success";

?>

To check whether the file is uploaded you can go to http://arunneeraj.com/uploads/
The link lists all the file that are uploaded.

Once again this is the error am getting
B4X:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>501 Method Not Implemented</title>
</head><body>
<h1>Method Not Implemented</h1>
<p>GET to /upload_demo.php not supported.<br />
</p>
<p>Additionally, a 501 Method Not Implemented
error was encountered while trying to use an ErrorDocument to handle the request.</p>
</body></html>


Can any one check on these???
 
Upvote 0
Top