Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling asmx web Service from Android errors: "java.io.IOException:HTTP request failed, HTTP status: 500"

I'm trying to call .asmx web service from Android. Below you can see my code. It's working when I use it for another web service but it doesn't work for one I need to use. The problem is "java.io.IOException:HTTP request failed, HTTP status: 500" exception. Firstly i assume that the problem is from the web service side. However it works when i try to reach using Devexpress and .NET.

I tried to get same error from Devexpress, when I remove "contentType: "application/json; charset=utf-8"," line.

Note: There is no error at web service definitions.

private class KullaniciServiceAsync extends AsyncTask {

    protected void onPreExecute(){
        Toast.makeText(getApplicationContext(), "Kullanici Bilgileri Alınıyor...", Toast.LENGTH_SHORT).show();
    }
    @Override
    protected KullaniciBilgisiGetir doInBackground(String... Str) {
        try {
            //ArrayList<HeaderProperty> headerProperty = new ArrayList<HeaderProperty>();  
            //headerProperty.add(new HeaderProperty("Content-Type", "application/json; charset=utf-8")); 
            k = new KullaniciBilgisiGetir();    
            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
            request.addProperty("UserId","1234567890");
            request.addProperty("Password",Pass);
            request.addProperty("Kod",Kod);
            request.addProperty("Sifre",Sifre);
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet = true;
            envelope.setOutputSoapObject(request);
            Log.e("Request",request.toString());
            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
            androidHttpTransport.debug = true;
            try{
                 androidHttpTransport.call(SOAP_ACTION, envelope);
                 SoapObject response = (SoapObject) envelope.getResponse();
                 if (response.hasProperty("KResult")) {
                    if (response.getPropertyAsString("KResult") == null) {
                      k.setKullaniciRespond(null);
                    } else {
                      k.setKullaniciRespond(response.getPropertyAsString("KResult"));
                    }
                 }

             }catch(Exception e){
                 Log.e("httpTRYCATCH", e.toString());
             }
        } catch (Exception e) {
          Log.e("ilkTRY",e.toString());
        }              
        return k;
    }

    protected void onPostExecute(KullaniciBilgisiGetir e){
        txt1.setText("ResponseText   ->" + e.getKullaniciRespond());
        //txt2.setText("bu "+e.getResponse());
        //txt3.setText("Count "+count);
    }

}
like image 522
user00001 Avatar asked Aug 12 '26 22:08

user00001


1 Answers

java.io.IOEXCEPTION

Signals that an I/O exception of some sort has occurred. This class is the general class of exceptions produced by failed or interrupted I/O operations.

The Web server encountered an unexpected condition that prevented it from fulfilling the request by the client for access to the requested URL.

May be something is wrong at the server end, but the server can not be more specific about the error condition in its response.

therefore it returns it as a error code 500 which means there was an error at server end.

chances of getting this error might be

  1. The inputs or values that require to be passed for the method on server side and in your code side are different.
  2. May be your inputs were right but at some point the server failed to process output at his end and given you the response 500

How can it be resolved?

You will have to ask system administrator to check the error log at his end(if any log is used on their side).If the error is logged you will know the exact reason.

like image 150
NetStarter Avatar answered Aug 15 '26 12:08

NetStarter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!