Soap请求获得403错误

时间:2018-05-29 12:39:16

标签: android soap ksoap2

我在下面使用Ksoap2库发了一个soap请求。我在使用这段代码的时候得到了响应代码为403.I已搜索并发现Ksoap2库在android.But中与SOAP API集成时非常有用我无法弄清楚问题。

SOAP API请求:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="myUrl">
                      <soapenv:Header/>
                      <soapenv:Body>
                        <GetClients>
                          <Request>
                            <SourceCredentials>
                              <SourceName>{SourceName}</SourceName>
                              <Password>{Password}</Password>
                              <SiteIDs>
                                <int>{SiteID}</int>
                              </SiteIDs>
                            </SourceCredentials>
                            <XMLDetail>Full</XMLDetail>
                            <PageSize>0</PageSize>
                            <CurrentPageIndex>0</CurrentPageIndex>
                          </Request>
                        </GetClients>
                      </soapenv:Body>
                    </soapenv:Envelope>

我的Android代码是:

 SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

                SoapObject sourcecredentials = new SoapObject(SOAP_ACTION, "SourceCredentials");
                PropertyInfo info = new PropertyInfo();
                info.setName("SourceName");
                info.setValue("MySourceName");
                sourcecredentials.addProperty(info);

                PropertyInfo info2 = new PropertyInfo();
                info2.setName("Password");
                info2.setValue("myPassword");
                sourcecredentials.addProperty(info2);

               PropertyInfo info3 = new PropertyInfo();
                info3.setName("SiteIDs");
                info3.setValue(MySiteid);
                sourcecredentials.addProperty(info3);

              //This also I tried
                /*SoapObject soapSiteids = new SoapObject(NAMESPACE, "SiteIDs");
                soapSiteids.addProperty("int", MySiteId);
                sourcecredentials.addProperty("SiteIDs",soapSiteids);*/

                request.addProperty("SourceCredentials", sourcecredentials);

                request.addProperty("XMLDetail", "Full");
                request.addProperty("PageSize", "10");
                request.addProperty("CurrentPageIndex", "0");
                request.addProperty("ScheduleType", "Appointment");


                SoapSerializationEnvelope envelope =  new SoapSerializationEnvelope(SoapEnvelope.VER11);
                envelope.setOutputSoapObject(request);

                HttpTransportSE httpTransportSE = new HttpTransportSE("My WSDL Url");

                try {
                    httpTransportSE.call(SOAP_ACTION, envelope);
                    SoapPrimitive soapPrimitive = (SoapPrimitive)envelope.getResponse();
                    result = soapPrimitive.toString();
                } catch (Exception e) {
                    e.printStackTrace();
                }

我正在做这样的403 http错误。如果我在上面的代码中做错了什么,请帮助我。谢谢提前

1 个答案:

答案 0 :(得分:0)

  

当您调用服务并获得403错误时,可能会发生错误   由于以下原因。

  1. 请求中的用户代理或其他标头导致了 服务拒绝连接。也许缺少标题?
  2. 您正在发送身份验证凭据,但该帐户是 禁止/禁用。
  3. 您所在的远程主机被防火墙阻止。
  4. 您已达到对网络服务的限制,他们是 阻止任何进一步的连接