80,351
社区成员
发帖
与我相关
我的任务
分享
03-02 11:52:37.981 18005-18059/first2.hc.tess W/System.err: java.io.FileNotFoundException: http://10.6.94.170/CreateServices/Service1.asmx
03-02 11:52:37.981 18005-18059/first2.hc.tess W/System.err: at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:177)
03-02 11:52:37.981 18005-18059/first2.hc.tess W/System.err: at first2.hc.tess.MainActivity.GetStudentService(MainActivity.java:103)
03-02 11:52:37.981 18005-18059/first2.hc.tess W/System.err: at first2.hc.tess.MainActivity$2.run(MainActivity.java:61)
POST /CreateServices/Service1.asmx HTTP/1.1
Host: 10.6.94.170
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/selectAllStudentInfor"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<selectAllStudentInfor xmlns="http://tempuri.org/" />
</soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<selectAllStudentInforResponse xmlns="http://tempuri.org/">
<selectAllStudentInforResult>
<Student>
<Name>string</Name>
<Number>string</Number>
</Student>
<Student>
<Name>string</Name>
<Number>string</Number>
</Student>
</selectAllStudentInforResult>
</selectAllStudentInforResponse>
</soap:Body>
</soap:Envelope>
public void GetStudentService() {
String ServerUrl = "http://10.6.94.170/CreateServices/Service1.asmx";
//soapAction = 命名空间 + 方法名
String soapAction = "http://tempuri.org/selectAllStudentInfor";
//拼凑requestData
String soap = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
+ "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+ "<soap:Body>";
String mreakString = "";
mreakString = "<selectAllStudentInfor xmlns=\"http://tempuri.org/\">";
String soap2 = "</soap:Body> </soap:Envelope>";
String requestData = soap + mreakString + soap2;
//其上所有的数据都是在拼凑requestData,即向服务器发送的数据
try {
URL url = new URL(ServerUrl); //指定服务器地址
HttpURLConnection con = (HttpURLConnection) url.openConnection();//打开链接
byte[] bytes = requestData.getBytes("utf-8"); //指定编码格式,可以解决中文乱码问题
con.setDoInput(true); //指定该链接是否可以输入
con.setDoOutput(true); //指定该链接是否可以输出
con.setUseCaches(false); //指定该链接是否只用caches
con.setConnectTimeout(6000); // 设置超时时间
con.setRequestMethod("POST"); //指定发送方法名,包括Post和Get。
con.setRequestProperty("Content-Type", "text/xml;charset=utf-8"); //设置(发送的)内容类型
con.setRequestProperty("SOAPAction", soapAction); //指定soapAction
con.setRequestProperty("Content-Length", bytes.length + ""); //指定内容长度
//发送数据
OutputStream outStream = con.getOutputStream();
outStream.write(bytes);
// if(con.getResponseCode() == 200){
//获取数据
InputStream inputStream = con.getInputStream();
String text = Utils.getTextFromStream(inputStream);