【发布时间】:2019-01-03 01:59:45
【问题描述】:
大家好,如何请求使用 android 改造来实现这个肥皂请求,但我得到 400 响应代码有没有办法通过改造来实现这个?
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<ActivityId CorrelationId="e5bbf878-4503-4010-aab5-b81d422b66ba" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">f905b59e-f833-44cb-9760-3c6619dc8c6c</ActivityId>
</s:Header>
<s:Body>
<QueryMessage xmlns="http://tempuri.org/">
<messageSet xmlns:a="http://schemas.datacontract.org/2004/07/Sanay.Suip.Library" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:ActionId i:nil="true">?</a:ActionId>
<a:Ip>::1</a:Ip>
<a:Parameters>
<a:Parameter>
<a:Name>Username</a:Name>
<a:Value i:type="b:string" xmlns:b="http://www.w3.org/2001/XMLSchema">tipex</a:Value>
</a:Parameter>
<a:Parameter>
<a:Name>Password</a:Name>
<a:Value i:type="b:string" xmlns:b="http://www.w3.org/2001/XMLSchema">123456</a:Value>
</a:Parameter>
</a:Parameters>
<a:Title>Authenticate</a:Title>
<a:Token>?</a:Token>
<a:Username>tipex</a:Username>
</messageSet>
</QueryMessage>
</s:Body>
这是我的模型类
@Root(name = "s:信封") @Namespace(前缀 = "s", 引用 = "http://schemas.xmlsoap.org/soap/envelope/")
公共类信封{
@Element(name = "s:Body")
private Body body;
public Body getBody() {
return body;
}
public void setBody(Body body) {
this.body = body;
}
}
@Root(name = "x:Body")
公共类正文{
@Element(name = "QueryMessage")
private QueryMessage queryMessage;
public QueryMessage getQueryMessage() {
return queryMessage;
}
public void setQueryMessage(QueryMessage queryMessage) {
this.queryMessage = queryMessage;
}
}
@Root(name = "QueryMessage")
@Namespace(reference = "http://tempuri.org/")
公共类 QueryMessage {
@Element(name = "messageSet")
private MessageSet messageSet;
public MessageSet getMessageSet() {
return messageSet;
}
public void setMessageSet(MessageSet messageSet) {
this.messageSet = messageSet;
}
}
@Root (name = "messageSet")
@命名空间列表({ @Namespace(前缀 = "a", 参考 = "http://schemas.datacontract.org/2004/07/Sanay.Suip.Library"), @命名空间(前缀=“我”,参考=“http://www.w3.org/2001/XMLSchema-instance”) })
公共类消息集{
@Element(name = "ActionId",required = false)
private String actionId;
@Element(name = "Ip")
private String ip;
@ElementList (name = "Parameters")
private List<ModelParameter> modelParameterList;
@Element(name = "Title")
private String title;
@Element(name = "Token",required = false)
private String token;
@Element(name = "Username")
private String username;
public String getActionId() {
return actionId;
}
public void setActionId(String actionId) {
this.actionId = actionId;
}
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public List<ModelParameter> getModelParameterList() {
return modelParameterList;
}
public void setModelParameterList(List<ModelParameter> modelParameterList) {
this.modelParameterList = modelParameterList;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}
@Root(name = "Parameter")
公共类模型参数 {
@Element(name = "Name")
private String name;
@Element(name = "Value")
private String value;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
【问题讨论】:
-
您在上面的代码中遇到了什么问题?详细描述您的问题。
-
@kiranBiradar 我的请求返回错误代码 400 !我错过了什么吗???
-
你能说明你是如何解组 xml 的吗?
-
@kiranBiradar 我的 xml 请求,正如您在问题顶部看到的那样,向我返回响应 200。我创建了这些模型,您可以在我的 xml 请求下方看到;根据我的 xml 请求并在 android studio 中我用改造对其进行了测试,我得到响应 400 我想我的问题是没有将命名空间设置为我的 VALUE 元素,我不知道该怎么做
-
好的,我可以帮你设置命名空间。