1- I am building an application front/back end using Visual Studio 2022 as the back end for Image upload file and it is tested using Postman it uploads the image to the server Successfully
Postman test Image
2- I am trying to call the API from android studio and I am using the following code
void DoActualRequest(File f)
{
String Excep_tion;
String url="http://192.168.1.6:46829/api/ImageUpload";
Toast.makeText(this, "OKHTTP3_VJ_Files , Calles actual Reuquest"+url,Toast.LENGTH_SHORT).show();
new Thread()
{
@Override
public void run()
{
final int flag;
try
{
OkHttpClient client=new OkHttpClient();
RequestBody requestBody=new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("files",f.getName(),RequestBody.create(MediaType.parse("image/jpeg"),f) )
.build();
okhttp3.Request request=new okhttp3.Request.Builder()
.url(url)
.post(requestBody)
.build();
try {
okhttp3.Response response = client.newCall(request).execute();
if(response.isSuccessful()) {
Toast.makeText(MainActivity.this, "successful response", Toast.LENGTH_SHORT).show();
flag=1;
}
else {
Toast.makeText(MainActivity.this, "" + response.body(), Toast.LENGTH_SHORT).show();
flag=0;
}
runOnUiThread(new Runnable() {
@Override
public void run() {
if(flag==1)
Toast.makeText(MainActivity.this, "OK", Toast.LENGTH_SHORT).show();
else
Toast.makeText(MainActivity.this, "NOT OK", Toast.LENGTH_SHORT).show();
}
});
}catch(Exception ex)
{
Toast.makeText(MainActivity.this, ex.getMessage().toString(), Toast.LENGTH_SHORT).show();
ex.printStackTrace();
}
}catch(Exception ex)
{
Toast.makeText(MainActivity.this, ex.getCause().toString(), Toast.LENGTH_SHORT).show();
ex.printStackTrace();
}
}
}.start();
}
3-when I am trying to use the above function I got error : 400 Bad request ? even it is tested in postman ,i tried the to test other Browser but the problem persists , Any explanation for this error 5- Also I directly tested the link in the Browser i got the following Error when using the IP address 192.168.1.6
Error 400
4-and when using the URL : http://localhost:46829/api/ImageUpload i got the folowing Error 405
Error 405
thanks in advance
What I have tried:
actually i tested the Back end with Postman and it is working