我正在使用ksoap2进行xmlparsing。我已经在我的library.And中添加了ksoap2.jar文件,并编写了以下代码
import java.io.IOException;
import java.util.Vector;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransport;
public class KsoapMidlet extends MIDlet {
Display display;
String strUserName= "Hello";
String strPassword = "World";
long ParentID;
String ChildIMEINumber;
String ChildName;
String serviceUrl = "http://www.semaphore.co.in/ChildTrackerService/ChildTrackerService.asmx";
String serviceNameSpace = "http://tempuri.org/";
String soapAction ="http://tempuri.org/AddChild";
String methodName = "AddChild";
Vector v=new Vector();
public void startApp() {
display = Display.getDisplay(this);
parsing();
// v.addElement("Hello");
// v.addElement("World");
// Constants d=new Constants();
// d.callSoap(methodName,v);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
notifyDestroyed();
}
public void parsing(){
SoapObject request = new SoapObject(serviceNameSpace,methodName);
request.addProperty("strUserName", strUserName);
request.addProperty("strPassword", strPassword);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
envelope.bodyOut = request;
envelope.encodingStyle = SoapSerializationEnvelope.ENC;
HttpTransport transport = new HttpTransport("http://www.semaphore.co.in/ChildTrackerService/ChildTrackerService.asmx");
transport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
transport.debug = true;
String result = null;
try {
transport.call("http://tempuri.org/" + methodName, envelope);
result = (envelope.getResponse()).toString();
System.out.println("***********************result********************************");
System.out.println("result=="+result);
System.out.println("Result :" + result.toString());
}
catch (org.xmlpull.v1.XmlPullParserException ex2) {
System.out.println("XmlPullParserException :" + ex2.toString());
System.out.println("Request \n" + transport.requestDump);
System.out.println("Response \n" + transport.responseDump);
} catch (SoapFault sf) {
System.out.println("SoapFault :" + sf.faultstring);
System.out.println("Request \n" + transport.requestDump);
System.out.println("Response \n" + transport.responseDump);
} catch (IOException ioe) {
System.out.println("IOException :" + ioe.toString());
System.out.println("Request \n" + transport.requestDump);
System.out.println("Response \n" + transport.responseDump);
}
}
}但是我遇到了IO异常-transport.call("http://tempuri.org/" + methodName, envelope);
错误消息是:--
IOException :java.io.IOException: malformed header field <html>请求<?xml version="1.0" encoding="UTF-8"?><v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/"><v:Header /><v:Body><AddChild xmlns="http://tempuri.org/" id="o0" c:root="1"><strUserName i:type="d:string">Hello</strUserName><strPassword i:type="d:string">World</strPassword></AddChild></v:Body></v:Envelope>
响应
null发布于 2011-07-25 13:06:45
我也面临着同样的问题。我解决这个问题的方法是更改手机上的配置文件设置。转到GPRS连接设置并将协议更改为HTTP (它以前在WAP上)。
发布于 2011-05-16 19:26:09
我假设HTTP响应是一个带有自定义HTML错误页面的HTTP404。这是我唯一能想象到如何在web服务中得到答案的可能性。
可能是transport.call(..)中的URL错误或服务器端的web服务未处于活动状态。
我建议使用本地http代理,比如WebScarab (Java)或Fiddler (.Net),并将调用重定向到这个本地代理。然后,您将看到服务器作为响应发送的内容。
https://stackoverflow.com/questions/4932316
复制相似问题