越来越java.io.IOException异常:HTTP请求失败,HTTP状态:404 ksoap2而传递XML数据SOAP1.2机器人 [英] getting java.io.IOException: HTTP request failed, HTTP status: 404 in ksoap2 while passing xml data to soap1.2 android
问题描述
我要通过
< XML版本=1.0编码=UTF-8&GT?;
&LT;你好&GT;&lt;用户名&GT; test@test.com< /用户名&gt;
&LT;密码&GT;测试&LT; /密码&GT;&LT; /你好&GT;
到
WSDL
&LT; WSDL:定义的xmlns:WSDL =http://schemas.xmlsoap.org/wsdl/的xmlns:肥皂=http://schemas.xmlsoap.org/ WSDL / SOAP /的xmlns:SOAPENC =http://schemas.xmlsoap.org/soap/encoding/的xmlns:WSU =http://docs.oasis-open.org/wss/2004/01/oasis- 200401-WSS-wssecurity型多功能1.0.xsd的xmlns:XSD =http://www.w3.org/2001/XMLSchema的xmlns:SOAP12 =http://schemas.xmlsoap.org/wsdl/soap12/ 的xmlns:TNS =http://tempuri.org/的xmlns:WSA =http://schemas.xmlsoap.org/ws/2004/08/addressing的xmlns:WSP =HTTP://schemas.xmlsoap .ORG / WS / 2004/09 /政策的xmlns:WSAP =http://schemas.xmlsoap.org/ws/2004/08/addressing/policy的xmlns:WSAW =http://www.w3.org / 2006/05 /寻址/ WSDL的xmlns:MSC =http://schemas.microsoft.com/ws/2005/12/wsdl/contract的xmlns:wsa10 =http://www.w3.org/2005 / 08 /寻址的xmlns:WSX =http://schemas.xmlsoap.org/ws/2004/09/mex的xmlns:WSAM =http://www.w3.org/2007/05/addressing/metadata NAME =SilentManagerAPI的targetNamespace =http://tempuri.org/&GT;
&LT; WSP:政策WSU:ID =WSHttpBinding_ISilentManagerAPI_policy&GT;
&LT; WSP:ExactlyOne上&GT;
&LT; WSP:所有&GT;
&LT; WSAW:UsingAddressing /&GT;
&LT; / WSP:所有&GT;
&LT; / WSP:ExactlyOne上&GT;
&LT; / WSP:政策&GT;
&LT; WSDL:类型&GT;
&LT; XSD:架构的targetNamespace =http://tempuri.org/Imports&GT;
&LT; XSD:导入的schemaLocation =http://myurl.com/Service.svc?xsd=xsd0命名空间=http://tempuri.org//&GT;
&LT; XSD:导入的schemaLocation =http://myurl.com/Service.svc?xsd=xsd1命名空间=http://schemas.microsoft.com/2003/10/Serialization//&GT;
&LT; / XSD:模式&GT;
&LT; / WSDL:类型&GT;
&LT; WSDL:消息名称=ISilentManagerAPI_Service_InputMessage&GT;
&LT; WSDL:部分名称=参数元素=TNS:服务/&GT;
&LT; / WSDL:消息&GT;
&LT; WSDL:消息名称=ISilentManagerAPI_Service_OutputMessage&GT;
&LT; WSDL:部分名称=参数元素=TNS:ServiceResponse/&GT;
&LT; / WSDL:消息&GT;
&LT; WSDL:portType的名称=ISilentManagerAPI&GT;
&LT; WSDL:操作名称=服务&GT;
&LT; WSDL:输入WSAW:行动=http://tempuri.org/ISilentManagerAPI/Service消息=TNS:ISilentManagerAPI_Service_InputMessage/&GT;
&LT; WSDL:输出WSAW:行动=http://tempuri.org/ISilentManagerAPI/ServiceResponse消息=TNS:ISilentManagerAPI_Service_OutputMessage/&GT;
&LT; / WSDL:操作&gt;
&LT; / WSDL:端口类型&GT;
&LT; WSDL:绑定名称=WSHttpBinding_ISilentManagerAPITYPE =TNS:ISilentManagerAPI&GT;
&LT; WSP:PolicyReference URI =#WSHttpBinding_ISilentManagerAPI_policy/&GT;
&LT; SOAP12:绑定传输=http://schemas.xmlsoap.org/soap/http/&GT;
&LT; WSDL:操作名称=服务&GT;
&LT; SOAP12:操作的soapAction =http://tempuri.org/ISilentManagerAPI/Service的风格=文件/&GT;
&LT; WSDL:输入&GT;
&LT; SOAP12:身体使用=文字/&GT;
&LT; / WSDL:输入&GT;
&LT; WSDL:输出&GT;
&LT; SOAP12:身体使用=文字/&GT;
&LT; / WSDL:输出&GT;
&LT; / WSDL:操作&gt;
&LT; / WSDL:绑定&GT;
&LT; WSDL:服务名称=SilentManagerAPI&GT;
&LT; WSDL:端口名称=WSHttpBinding_ISilentManagerAPI绑定=TNS:WSHttpBinding_ISilentManagerAPI&GT;
&LT; SOAP12:地址位置=http://myurl.com/Service.svc/Service.svc/&GT;
&LT; wsa10:EndpointReference的&GT;
&LT; wsa10:地址&gt;
http://myurl.com/Service.svc/Service.svc
&LT; / wsa10:地址&gt;
&LT; / wsa10:EndpointReference的&GT;
&LT; / WSDL:端口&GT;
&LT; / WSDL:服务&GT;
&LT; / WSDL:定义&GT;
code尝试:
进口android.os.AsyncTask;
进口android.os.Bundle;
进口android.util.Log;
进口android.widget.TextView;
进口android.app.Activity;
进口android.app.Dialog;
进口android.app.ProgressDialog;
进口android.content.DialogInterface;
进口android.content.DialogInterface.OnCancelListener;
进口java.io.Writer中;
进口org.ksoap2 *。
进口org.ksoap2.serialization *。
进口org.ksoap2.transport *。
进口org.xmlpull.v1.XmlSerializer;
公共类MainActivity延伸活动{
私有静态最后弦乐METHOD_NAME =服务;
私有静态最后弦乐NAMESPACE =http://tempuri.org/;
私有静态最后字符串的URL =http://myurl.com/Service.svc;
最后弦乐SOAP_ACTION =http://tempuri.org/ISilentManagerAPI/Service;
TextView的电视;
StringBuilder的某人;
私人XmlSerializer的作家;
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
电视=新的TextView(本);
SB =新的StringBuilder();
新testReq()执行();
tv.setText(sb.toString());
的setContentView(电视);
}
类testReq扩展的AsyncTask&LT;虚空,虚空,虚空&GT; {
对话对话框;
@覆盖
在preExecute保护无效(){
// TODO自动生成方法存根
super.on preExecute();
对话框= ProgressDialog.show(MainActivity.this,请等待......,
测试........);
dialog.setCancelable(真正的);
dialog.setOnCancelListener(新OnCancelListener(){
@覆盖
公共无效OnCancel的(DialogInterface对话){
// TODO自动生成方法存根
取消(真);
}
});
}
@覆盖
保护无效onPostExecute(无效的结果){
// TODO自动生成方法存根
super.onPostExecute(结果);
dialog.dismiss();
}
@覆盖
保护无效doInBackground(虚空...... PARAMS){
// TODO自动生成方法存根
呼叫();
返回null;
}
}
公共无效调用(){
尝试 {
SoapObject请求=新SoapObject(命名空间METHOD_NAME);
的PropertyInfo REQ =新的PropertyInfo();
req.name =你好;
req.type =为String.class;
req.setValue(&LT;你好&GT;+&lt;用户名&GT; test@test.com< /用户名&gt;
+&LT;密码&GT; test123&LT; /密码&gt;中+&LT; /你好&GT;);
request.addProperty(REQ);
SoapSerializationEnvelope包=新SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = TRUE;
envelope.setOutputSoapObject(要求);
HttpTransportSE androidHttpTransport =新HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION,包);
SoapPrimitive结果=(SoapPrimitive)envelope.getResponse();
串resultData = result.toString();
Log.i(结果,+ resultData);
sb.append(resultData +\ N);
}赶上(例外五){
sb.append(错误:\ n+ e.getMessage()+\ N);
e.printStackTrace();
}
}
}
我使用网络许可的AndroidManifest.xml
&LT;使用-权限的Android:名称=android.permission.INTERNET对/&GT;
,输出会像
&LT;你好&GT;
&lt;用户名&GT;任何&LT; /用户名&gt;
&LT; myoutputdata&GT;
。
。返回数据
。
&LT; / myoutputdata&GT;
&LT; /无声GT;
尝试这种code得到后除了
LogCat中
08-01 13:27:53.240:W / System.err的(10915):java.io.IOException异常:HTTP请求失败,HTTP状态:404
08-01 13:27:53.300:W / System.err的(10915):在org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:195)
08-01 13:27:54.370:W / System.err的(10915):在org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:116)
08-01 13:27:54.390:W / System.err的(10915):在org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:111)
08-01 13:27:54.410:W / System.err的(10915):在com.example.testeset.MainActivity.call(MainActivity.java:105)
08-01 13:27:54.440:W / System.err的(10915):在com.example.testeset.MainActivity $ testReq.doInBackground(MainActivity.java:80)
08-01 13:27:54.460:W / System.err的(10915):在com.example.testeset.MainActivity $ testReq.doInBackground(MainActivity.java:1)
08-01 13:27:54.470:W / System.err的(10915):在android.os.AsyncTask $ 2.call(AsyncTask.java:264)
08-01 13:27:54.480:W / System.err的(10915):在java.util.concurrent.FutureTask中$ Sync.innerRun(FutureTask.java:305)
08-01 13:27:54.490:W / System.err的(10915):在java.util.concurrent.FutureTask.run(FutureTask.java:137)
08-01 13:27:54.500:W / System.err的(10915):在android.os.AsyncTask $ SerialExecutor $ 1.运行(AsyncTask.java:208)
08-01 13:27:54.500:W / System.err的(10915):在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
08-01 13:27:54.500:W / System.err的(10915):在java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:569)
08-01 13:27:54.500:W / System.err的(10915):在java.lang.Thread.run(Thread.java:856)
在这里,我得到异常:
androidHttpTransport.call(SOAP_ACTION,包);
如果仍然具有现实意义。
首先,你应该改变网址
到 http://myurl.com/Service.svc/Service.svc
。这将解决404错误。
此外,您应该修改
SoapSerializationEnvelope包=新SoapSerializationEnvelope(SoapEnvelope.VER11);
到
SoapSerializationEnvelope包=新SoapSerializationEnvelope(SoapEnvelope.VER12);
此外,您应该添加 WSA:以
和 WSA:动作
标题是这样的:
元素e =新元素();
e.setName(到);
e.setNamespace(http://www.w3.org/2005/08/addressing);
e.addChild(Node.TEXThttp://myurl.com/Service.svc/Service.svc);
元素E1 =新元素();
e1.setName(行动);
e1.setNamespace(http://www.w3.org/2005/08/addressing);
e1.addChild(Node.TEXThttp://tempuri.org/ISilentManagerAPI/Service);
envelope.headerOut =新的元素[] {E,E1};
我希望这是有帮助的。
编辑:尝试改变 REQ
来:
的PropertyInfo REQ =新的PropertyInfo();
req.name =的xmlString;
req.namespace = NAMESPACE;
req.type =为String.class;
req.setValue("<hello><username>test@test.com</username><password>test</password></hello>");
request.addProperty(REQ);
即改变 req.name
到的xmlString
并设置名称空间。
i have to pass
<?xml version='1.0' encoding='utf-8' ?>
<hello><username>test@test.com</username>
<password>test</password></hello>
to
Wsdl
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:tns="http://tempuri.org/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" name="SilentManagerAPI" targetNamespace="http://tempuri.org/">
<wsp:Policy wsu:Id="WSHttpBinding_ISilentManagerAPI_policy">
<wsp:ExactlyOne>
<wsp:All>
<wsaw:UsingAddressing/>
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
<wsdl:types>
<xsd:schema targetNamespace="http://tempuri.org/Imports">
<xsd:import schemaLocation="http://myurl.com/Service.svc?xsd=xsd0" namespace="http://tempuri.org/"/>
<xsd:import schemaLocation="http://myurl.com/Service.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="ISilentManagerAPI_Service_InputMessage">
<wsdl:part name="parameters" element="tns:Service"/>
</wsdl:message>
<wsdl:message name="ISilentManagerAPI_Service_OutputMessage">
<wsdl:part name="parameters" element="tns:ServiceResponse"/>
</wsdl:message>
<wsdl:portType name="ISilentManagerAPI">
<wsdl:operation name="Service">
<wsdl:input wsaw:Action="http://tempuri.org/ISilentManagerAPI/Service" message="tns:ISilentManagerAPI_Service_InputMessage"/>
<wsdl:output wsaw:Action="http://tempuri.org/ISilentManagerAPI/ServiceResponse" message="tns:ISilentManagerAPI_Service_OutputMessage"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="WSHttpBinding_ISilentManagerAPI" type="tns:ISilentManagerAPI">
<wsp:PolicyReference URI="#WSHttpBinding_ISilentManagerAPI_policy"/>
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="Service">
<soap12:operation soapAction="http://tempuri.org/ISilentManagerAPI/Service" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="SilentManagerAPI">
<wsdl:port name="WSHttpBinding_ISilentManagerAPI" binding="tns:WSHttpBinding_ISilentManagerAPI">
<soap12:address location="http://myurl.com/Service.svc/Service.svc"/>
<wsa10:EndpointReference>
<wsa10:Address>
http://myurl.com/Service.svc/Service.svc
</wsa10:Address>
</wsa10:EndpointReference>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Code Tried :
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import java.io.Writer;
import org.ksoap2.*;
import org.ksoap2.serialization.*;
import org.ksoap2.transport.*;
import org.xmlpull.v1.XmlSerializer;
public class MainActivity extends Activity {
private static final String METHOD_NAME = "Service";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://myurl.com/Service.svc";
final String SOAP_ACTION = "http://tempuri.org/ISilentManagerAPI/Service";
TextView tv;
StringBuilder sb;
private XmlSerializer writer;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
tv = new TextView(this);
sb = new StringBuilder();
new testReq().execute();
tv.setText(sb.toString());
setContentView(tv);
}
class testReq extends AsyncTask<Void, Void, Void> {
Dialog dialog;
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
dialog = ProgressDialog.show(MainActivity.this, "Please Wait...",
"Testing........");
dialog.setCancelable(true);
dialog.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
// TODO Auto-generated method stub
cancel(true);
}
});
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
dialog.dismiss();
}
@Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
call();
return null;
}
}
public void call() {
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo req = new PropertyInfo();
req.name = "hello";
req.type = String.class;
req.setValue("<hello>" + "<username>test@test.com</username>"
+ "<password>test123</password>" + "</hello>");
request.addProperty(req);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive result = (SoapPrimitive) envelope.getResponse();
String resultData = result.toString();
Log.i("Result", "" + resultData);
sb.append(resultData + "\n");
} catch (Exception e) {
sb.append("Error:\n" + e.getMessage() + "\n");
e.printStackTrace();
}
}
}
i am using internet permission in AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET"/>
and output will be like
<hello>
<username>any</username>
<myoutputdata>
.
. return data
.
</myoutputdata>
</silent>
After Trying this code getting exception
LogCat
08-01 13:27:53.240: W/System.err(10915): java.io.IOException: HTTP request failed, HTTP status: 404
08-01 13:27:53.300: W/System.err(10915): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:195)
08-01 13:27:54.370: W/System.err(10915): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:116)
08-01 13:27:54.390: W/System.err(10915): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:111)
08-01 13:27:54.410: W/System.err(10915): at com.example.testeset.MainActivity.call(MainActivity.java:105)
08-01 13:27:54.440: W/System.err(10915): at com.example.testeset.MainActivity$testReq.doInBackground(MainActivity.java:80)
08-01 13:27:54.460: W/System.err(10915): at com.example.testeset.MainActivity$testReq.doInBackground(MainActivity.java:1)
08-01 13:27:54.470: W/System.err(10915): at android.os.AsyncTask$2.call(AsyncTask.java:264)
08-01 13:27:54.480: W/System.err(10915): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
08-01 13:27:54.490: W/System.err(10915): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
08-01 13:27:54.500: W/System.err(10915): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
08-01 13:27:54.500: W/System.err(10915): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
08-01 13:27:54.500: W/System.err(10915): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
08-01 13:27:54.500: W/System.err(10915): at java.lang.Thread.run(Thread.java:856)
Here i am getting Exception:
androidHttpTransport.call(SOAP_ACTION, envelope);
If still relevant..
First of all, you should change URL
to http://myurl.com/Service.svc/Service.svc
. It will solve 404 error.
Further you should change
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
to
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
Further you should add wsa:To
and wsa:Action
headers like this:
Element e = new Element();
e.setName("To");
e.setNamespace("http://www.w3.org/2005/08/addressing");
e.addChild(Node.TEXT,"http://myurl.com/Service.svc/Service.svc");
Element e1 = new Element();
e1.setName("Action");
e1.setNamespace("http://www.w3.org/2005/08/addressing");
e1.addChild(Node.TEXT,"http://tempuri.org/ISilentManagerAPI/Service");
envelope.headerOut = new Element[]{e,e1};
I hope it is helpful.
Edit: Try to change req
to:
PropertyInfo req = new PropertyInfo();
req.name = "xmlstring";
req.namespace=NAMESPACE;
req.type = String.class;
req.setValue("<hello><username>test@test.com</username><password>test</password></hello>");
request.addProperty(req);
ie change req.name
to xmlstring
and set namespace.
这篇关于越来越java.io.IOException异常:HTTP请求失败,HTTP状态:404 ksoap2而传递XML数据SOAP1.2机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!