我正在尝试从 Android 调用 .asmx 网络服务。下面你可以看到我的代码。当我将它用于另一个 Web 服务时它正在工作,但它不适用于我需要使用的一个。问题是“java.io.IOException:HTTP 请求失败,HTTP 状态:500”异常。首先,我假设问题出在 Web 服务端。但是,当我尝试使用 Devexpress 和 .NET 时,它会起作用。
当我删除“contentType:”application/json; 时,我试图从 Devexpress 得到同样的错误。charset=utf-8"," 行。
注意:Web 服务定义没有错误。
私有类 KullaniciServiceAsync 扩展 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);
}
}