1

Everything was working fine until I installed SSL certificate on my websites now i get this error when connecting to c# web api using IIS 10 from android . My code works on android 6 and above but not on android 4. Here is my code

protected String doInBackground(String... strings) {
    List<File> mFiles=new ArrayList<>();

    String urlString = Common.URL+"SaveImage";

    try {
        HttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost(urlString);
        final List<FileBody> mFileBody=new ArrayList<>();
        for(int i=0;i<Common.ImagePathList.size();i++){
            FileBody bin1 = new FileBody(new File(Common.ImagePathList.get(i)));
            mFileBody.add(bin1);
        }
        Looper.prepare();
        MultipartEntityBuilder reqEntity = MultipartEntityBuilder.create();
        reqEntity.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
        for(int i=0;i<  mFileBody.size();i++){
            reqEntity.addPart("Photo"+i,mFileBody.get(i));
        }

        //  reqEntity.addTextBody("size",""+Common.ImagePathList.size(), cz.msebera.android.httpclient.entity.ContentType.parse(ContentType.TEXT_PLAIN));
        reqEntity.addTextBody("adId",Common.AdId);
        post.setEntity((HttpEntity) reqEntity.build());

        //socketFactory.createSocket().connect(client.);
        HttpResponse response = client.execute(post);
        HttpEntity resEntity = response.getEntity();
        final String response_str = EntityUtils.toString(resEntity);

        if (resEntity != null) {
            Log.i("RESPONSE", response_str);
            runOnUiThread(new Runnable() {
                public void run() {
                    try {
                        mFileBody.clear();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }});
            return response_str;
        }
    } catch (Exception ex){
        Log.e("Debug", "error: " + ex.getMessage(), ex);
        Toast.makeText(getApplicationContext(), ""+ ex.getMessage(), Toast.LENGTH_LONG).show();
    }

    return null;
}

I tried postman and to see if it was server issue but it works fine in postman but copying the java auto code from postman doesn't work in android and produced Response code 400

Thanks in advance

irfandar
  • 1,690
  • 1
  • 23
  • 24

0 Answers0