从Android调用asmx web服务时出错:“;IOException:HTTP请求失败,HTTP状态:500“;
我正在尝试从Android调用.asmx web服务。下面你可以看到我的代码。当我将它用于另一个web服务时,它是有效的,但对于我需要使用的web服务,它不起作用。 问题是“java.io.IOException:HTTP请求失败,HTTP状态:500”异常。 首先,我假设问题来自web服务方面。但是,当我尝试使用Devexpress和.NET访问时,它会起作用 当我删除“contentType:”application/json时,我试图从Devexpress获得相同的错误;字符集=utf-8“,行 注意:web服务定义没有错误 私有类KullaniServiceAsync扩展异步任务{从Android调用asmx web服务时出错:“;IOException:HTTP请求失败,HTTP状态:500“;,android,web-services,asmx,Android,Web Services,Asmx,我正在尝试从Android调用.asmx web服务。下面你可以看到我的代码。当我将它用于另一个web服务时,它是有效的,但对于我需要使用的web服务,它不起作用。 问题是“java.io.IOException:HTTP请求失败,HTTP状态:500”异常。 首先,我假设问题来自web服务方面。但是,当我尝试使用Devexpress和.NET访问时,它会起作用 当我删除“contentType:”application/json时,我试图从Devexpress获得相同的错误;字符集=utf-8
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);
}
}
受保护的void onPreExecute(){
Toast.makeText(getApplicationContext(),“Kullanici Bilgileri Alınıyor…”,Toast.LENGTH_SHORT.show();
}
@凌驾
受保护的KullaniciBilgisiGetir doInBackground(字符串…Str){
试一试{
//ArrayList headerProperty=新建ArrayList();
//添加(新的headerProperty(“内容类型”、“应用程序/json;字符集=utf-8”);
k=新的KullaniciBilgisiGetir();
SoapObject请求=新的SoapObject(名称空间、方法名称);
addProperty(“UserId”,“1234567890”);
request.addProperty(“密码”,Pass);
请求。添加属性(“Kod”,Kod);
请求。添加属性(“Sifre”,Sifre);
SoapSerializationEnvelope=新的SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(请求);
Log.e(“Request”,Request.toString());
HttpTransportSE androidHttpTransport=新的HttpTransportSE(URL);
androidHttpTransport.debug=true;
试一试{
调用(SOAP_操作,信封);
SoapObject响应=(SoapObject)信封.getResponse();
if(response.hasProperty(“KResult”)){
if(response.getPropertyAsString(“KResult”)==null){
k、 Setkulanicirespond(空);
}否则{
k、 SetkullanicRespond(response.getPropertyAsString(“KResult”);
}
}
}捕获(例外e){
Log.e(“httpTRYCATCH”,e.toString());
}
}捕获(例外e){
Log.e(“ilkTRY”,e.toString());
}
返回k;
}
执行后受保护的无效(Kullanicibilgisigetire e){
txt1.setText(“ResponseText->”+e.getkullanicisponse());
//txt2.setText(“bu”+e.getResponse());
//txt3.setText(“计数”+计数);
}
}
java.io.IOEXCEPTION
表示发生了某种类型的I/O异常。这个班是
由失败或中断的I/O产生的一般异常类别
行动
Web服务器遇到意外情况,无法满足客户端访问请求URL的请求
服务器端可能有问题,但服务器无法在其响应中更具体地说明错误情况
因此,它将其作为错误代码500返回,这意味着服务器端出现错误
出现此错误的可能性可能是
您必须要求系统管理员检查其端的错误日志(如果在其端使用了任何日志)。如果记录了错误,您将知道确切原因。请检查属性名称是否与web服务参数相同 比如,
request.addProperty("UserId","1234567890");
您的参数名是web服务上的UserId吗
您还可以按照本教程进行操作:此错误只能通过对Web服务器软件进行修复来解决。这不是客户端的问题,如何解决?我可以与系统管理员联系。但我应该告诉他他需要做什么。