gpt4 book ai didi

java - 使用 Ksoap 进行 Xml 解析

转载 作者:行者123 更新时间:2023-12-04 06:35:27 24 4
gpt4 key购买 nike

我正在使用 ksoap2 进行 xmlparsing。我在我的库中添加了 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

最佳答案

我遇到了同样的问题。我解决它的方法是更改​​手机上的配置文件设置。转到 GPRS 连接设置并将协议(protocol)更改为 HTTP(之前在 WAP 上)。

关于java - 使用 Ksoap 进行 Xml 解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4932316/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com