Android SOAP 请求返回 HTTP 响应 405 [英] Android SOAP request is returning HTTP Response 405

查看:36
本文介绍了Android SOAP 请求返回 HTTP 响应 405的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里看到了几个类似的问题,但我的有一个很大的不同.我能够使用我的登录 Web 客户端 Web 方法大约 9 个月,然后昨天下午我开始收到 405 响应.

下面是我的代码:

class Login extends AsyncTask{StringManipulator stringManipulator = new StringManipulator();字符串结果 = "";ParseSessionId parseSessionId = new ParseSessionId();@覆盖受保护的整数 doInBackground(String... args) {int 状态码;URLSet urlset = new URLSet();SoapLogin 登录 = new SoapLogin();字符串用户名 = "";字符串密码 = "";输入流内流;尝试 {HttpPost post = new HttpPost(new URI(urlset.getUrl()));post.setHeader("SOAPAction", urlset.getAction());post.setHeader("Content-Type", urlset.getContentType());Log.e("登录字符串实体", login.getSoapLogin(args[0].trim(), args[1].trim()));post.setEntity(new StringEntity(login.getSoapLogin(args[0].trim(), args[1].trim()));KeyStore trust = KeyStore.getInstance("BKS");可信加载(空,".toCharArray());SSLSocketFactory sslf = 新 SSLSocketFactory(可信);sslf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);SchemeRegistry schemeRegistry = new SchemeRegistry();schemeRegistry.register(new Scheme("https", sslf, 443));SingleClientConnManager cm = new SingleClientConnManager(post.getParams(), schemeRegistry);CustomHttpClient customHttpClient = new CustomHttpClient();HttpClient 客户端 = customHttpClient.getNewHttpClient();HttpResponse 响应 = client.execute(post);Log.e("response.getStatusLine()", "" + response.getStatusLine());statusCode = response.getStatusLine().getStatusCode();Header[] headers = response.getAllHeaders();for (标题 h : 标题) {Log.e("响应头", h.getName() + ":" + h.getValue());}HttpEntity entity = response.getEntity();如果(实体!= null){instream = entity.getContent();结果 = stringManipulator.convertStreamToString(instream);Log.e("结果", 结果);sessionID = parseSessionId.parseSessionId(result);流媒体关闭();}返回状态码;} 捕获(异常 e){返回空;}}@覆盖protected void onPostExecute(Integer resultCode) {如果(结果代码 == 200){//Toast.makeText(context, "Response: OK", Toast.LENGTH_LONG).show();} else if (resultCode == 400) {Toast.makeText(context, "Server Error: 400", Toast.LENGTH_LONG).show();} else if (resultCode == 500) {Toast.makeText(context, "Server Error: 500", Toast.LENGTH_LONG).show();} 别的 {Toast.makeText(context, "Server Error:" + resultCode, Toast.LENGTH_LONG).show();}}}

就像我说的,直到昨天下午这一切都很好.我使用 SOAP UI 在浏览器上进行测试,然后使用 StringManipulator 类构建 SOAP 消息.

最终的soap登录看起来像这样:

<soapenv:Header/><soapenv:Body><项目:登录><tem:login>用户名</tem:login><tem:password>password</tem:password></tem:登录></soapenv:Body></soapenv:信封>

响应状态行是:

<块引用>

HTTP/1.1 405 方法不被允许

响应正文是:

07-16 10:38:01.113: E/result(6877): <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">07-16 10:38:01.113:E/result(6877):<html xmlns="http://www.w3.org/1999/xhtml">07-16 10:38:01.113:E/result(6877):<head>07-16 10:38:01.113:E/result(6877):<title>IIS 8.5 详细错误 - 405.0 - 不允许的方法</title>07-16 10:38:01.113:E/result(6877):<style type="text/css">07-16 10:38:01.113: E/result(6877): <!--07-16 10:38:01.113: E/result(6877): body{margin:0;font-size:.7em;font-family:Verdana,Arial,Helvetica,sans-serif;}07-16 10:38:01.113: E/result(6877): code{margin:0;color:#006600;font-size:1.1em;font-weight:bold;}07-16 10:38:01.113: E/result(6877): .config_source code{font-size:.8em;color:#000000;}07-16 10:38:01.113: E/result(6877): pre{margin:0;font-size:1.4em;word-wrap:break-word;}07-16 10:38:01.113: E/result(6877): ul,ol{margin:10px 0 10px 5px;}07-16 10:38:01.113: E/result(6877): ul.first,ol.first{margin-top:5px;}07-16 10:38:01.113: E/result(6877): fieldset{padding:0 15px 10px 15px;word-break:break-all;}07-16 10:38:01.113: E/result(6877): .summary-container fieldset{padding-bottom:5px;margin-top:4px;}07-16 10:38:01.113: E/result(6877):legend.no-expand-all{padding:2px 15px 4px 10px;margin:0 0 0 -12px;}07-16 10:38:01.113: E/result(6877): legend{color:#333333;;margin:4px 0 8px -12px;_margin-top:0px;07-16 10:38:01.113:E/result(6877):字体粗细:粗体;字体大小:1em;}07-16 10:38:01.113: E/result(6877): a:link,a:visited{color:#007EFF;font-weight:bold;}07-16 10:38:01.113: E/result(6877): a:hover{text-decoration:none;}07-16 10:38:01.113: E/result(6877): h1{font-size:2.4em;margin:0;color:#FFF;}07-16 10:38:01.113: E/result(6877): h2{font-size:1.7em;margin:0;color:#CC0000;}07-16 10:38:01.113: E/result(6877): h3{font-size:1.4em;margin:10px 0 0 0;color:#CC0000;}07-16 10:38:01.113: E/result(6877): h4{font-size:1.2em;margin:10px 0 5px 0;07-16 10:38:01.113: E/result(6877): }#header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:"trebuchet MS",Verdana, sans-serif;07-16 10:38:01.113: E/result(6877): color:#FFF;background-color:#5C87B2;07-16 10:38:01.113: E/result(6877): }#content{margin:0 0 0 2%;position:relative;}07-16 10:38:01.113: E/result(6877): .summary-container,.content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;}07-16 10:38:01.113: E/result(6877): .content-container p{margin:0 0 10px 0;07-16 10:38:01.113: E/result(6877): }#details-left{width:35%;float:left;margin-right:2%;07-16 10:38:01.113: E/result(6877): }#details-right{width:63%;float:left;overflow:hidden;07-16 10:38:01.113: E/result(6877): }#server_version{width:96%;_height:1px;min-height:1px;margin:0 0 5px 0;padding:11px 2% 8px 2%;颜色:#FFFFFF;07-16 10:38:01.113: E/result(6877): background-color:#5A7FA5;border-bottom:1px solid #C1CFDD;border-top:1px solid #4A6C8E;font-weight:normal;07-16 10:38:01.113: E/result(6877): font-size:1em;color:#FFF;text-align:right;07-16 10:38:01.113: E/result(6877): }#server_version p{margin:5px 0;}07-16 10:38:01.113: E/result(6877): table{margin:4px 0 4px 0;width:100%;border:none;}07-16 10:38:01.113: E/result(6877): td,th{vertical-align:top;padding:3px 0;text-align:left;font-weight:normal;border:none;}07-16 10:38:01.113: E/result(6877): th{width:30%;text-align:right;padding-right:2%;font-weight:bold;}07-16 10:38:01.113: E/result(6877): thead th{background-color:#ebebeb;width:25%;07-16 10:38:01.113: E/result(6877): }#details-right th{width:20%;}07-16 10:38:01.113:E/result(6877):表 tr.alt td,表 tr.alt th{}07-16 10:38:01.113: E/result(6877): .highlight-code{color:#CC0000;font-weight:bold;font-style:italic;}07-16 10:38:01.113: E/result(6877): .clear{clear:both;}07-16 10:38:01.113: E/result(6877): .preferred{padding:0 5px 2px 5px;font-weight:normal;background:#006633;color:#FFF;font-size:.8em;}07-16 10:38:01.113: E/result(6877): -->07-16 10:38:01.113:E/result(6877):</style>07-16 10:38:01.113:E/结果(6877):07-16 10:38:01.113:E/result(6877):</head>07-16 10:38:01.113:E/result(6877):<body>07-16 10:38:01.113: E/result(6877): <div id="content">07-16 10:38:01.113: E/result(6877): <div class="content-container">07-16 10:38:01.113:E/result(6877):<h3>HTTP 错误 405.0 - 不允许的方法</h3>07-16 10:38:01.113:E/result(6877):<h4>由于使用了无效的方法(HTTP动词),您正在查找的页面无法显示.</h4>07-16 10:38:01.113:E/result(6877):</div>07-16 10:38:01.113: E/result(6877): <div class="content-container">07-16 10:38:01.113:E/result(6877):<fieldset><h4>最可能的原因:</h4>07-16 10:38:01.113:E/result(6877):
    <li>发送到 Web 服务器的请求使用了 HTTP 动词,配置为处理该请求的模块不允许使用该 HTTP 动词.</li><li>向服务器发送的请求包含无效的 HTTP 动词.</li><li>该请求是针对静态内容的,并且包含除 GET 或 HEAD 之外的 HTTP 动词.</li><li>使用 HTTP 动词 POST 将请求发送到虚拟目录,并且默认文档是不支持除 GET 或 HEAD 之外的 HTTP 动词的静态文件.</li>
07-16 10:38:01.113:E/result(6877):</fieldset>07-16 10:38:01.113:E/result(6877):</div>07-16 10:38:01.113: E/result(6877): <div class="content-container">07-16 10:38:01.113:E/result(6877):<fieldset><h4>可以尝试的事情:</h4>07-16 10:38:01.113:E/result(6877):
    <li>验证为此请求发送到的模块处理程序启用的动词列表,并确保该动词应允许用于网站.</li><li>检查 IIS 日志文件以查看请求不允许使用哪个谓词.</li><li>创建跟踪规则以跟踪此 HTTP 状态代码的失败请求.有关为失败的请求创建跟踪规则的详细信息,请单击 <a href="http://go.microsoft.com/fwlink/?LinkID=66439">此处</a>.
07-16 10:38:01.113:E/result(6877):</fieldset>07-16 10:38:01.113:E/result(6877):</div>07-16 10:38:01.113:E/结果(6877):07-16 10:38:01.113: E/result(6877): <div class="content-container">07-16 10:38:01.113:E/result(6877):<fieldset><h4>详细错误信息:</h4>07-16 10:38:01.113:E/result(6877):<div id="details-left">07-16 10:38:01.113: E/result(6877): <table border="0" cellpadding="0" cellspacing="0">07-16 10:38:01.113:E/result(6877):<tr class="alt"><th>Module</th><td>&nbsp;&nbsp;;StaticFileModule</td></tr>

就像我说的,这很奇怪,因为在昨天午饭前和昨天午饭后之间,我什么都没做……那为什么我会从服务器收到新的响应?

我对尝试的事情感到茫然.

解决方案

如果它有效,你去吃午饭,回来后它不再有效(正如你所说,你真的没有改变任何东西)然后其他人改变了一些东西.

您正在执行 POST,但出于某种原因,IIS 不允许对您正在访问的任何资源进行 POST(可能是 WCF .svc 扩展名?).似乎StaticFileModule"是根据您返回的错误页面抱怨的.

也许有人重新配置了服务器,现在您的请求由另一个处理程序处理?我建议您联系您的网络管理员或站点管理员,询问他们是否在您发现方法调用不再起作用的时间范围内重新配置了某些内容、安装了新软件、应用了更新等.

I see a couple of similar questions on here but mine has one big difference. I was able to use my login web client web method for about 9 months and then yesterday afternoon I started getting the 405 response.

Below is my code:

class Login extends AsyncTask<String, String, Integer> {
    StringManipulator stringManipulator = new StringManipulator();
    String result = "";
    ParseSessionId parseSessionId = new ParseSessionId();

    @Override
    protected Integer doInBackground(String... args) {
        int statusCode;

        URLSet urlset = new URLSet();
        SoapLogin login = new SoapLogin();

        String username = "";
        String password = "";

        InputStream instream;
        try {
            HttpPost post = new HttpPost(new URI(urlset.getUrl()));

            post.setHeader("SOAPAction", urlset.getAction());
            post.setHeader("Content-Type", urlset.getContentType());

            Log.e("login string entity", login.getSoapLogin(args[0].trim(), args[1].trim()));

            post.setEntity(new StringEntity(login.getSoapLogin(args[0].trim(), args[1].trim())));

            KeyStore trusted = KeyStore.getInstance("BKS");
            trusted.load(null, "".toCharArray());
            SSLSocketFactory sslf = new SSLSocketFactory(trusted);
            sslf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

            SchemeRegistry schemeRegistry = new SchemeRegistry();
            schemeRegistry.register(new Scheme("https", sslf, 443));
            SingleClientConnManager cm = new SingleClientConnManager(post.getParams(), schemeRegistry);
            CustomHttpClient customHttpClient = new CustomHttpClient();
            HttpClient client = customHttpClient.getNewHttpClient();

            HttpResponse response = client.execute(post);

            Log.e("response.getStatusLine()", "" + response.getStatusLine());
            statusCode = response.getStatusLine().getStatusCode();

            Header[] headers = response.getAllHeaders();
            for (Header h : headers) {
                Log.e("Reponse Header", h.getName() + ": " + h.getValue());
            }

            HttpEntity entity = response.getEntity();

            if (entity != null) {
                instream = entity.getContent();
                result = stringManipulator.convertStreamToString(instream);

                Log.e("result", result);
                sessionID = parseSessionId.parseSessionId(result);

                instream.close();
            }
            return statusCode;

        } catch (Exception e) {
            return null;
        }
    }

    @Override
    protected void onPostExecute(Integer resultCode) {
        if (resultCode == 200) {
        //  Toast.makeText(context, "Response: OK", Toast.LENGTH_LONG).show();

        } else if (resultCode == 400) {
            Toast.makeText(context, "Server Error: 400", Toast.LENGTH_LONG).show();

        } else if (resultCode == 500) {
            Toast.makeText(context, "Server Error: 500", Toast.LENGTH_LONG).show();

        } else {
            Toast.makeText(context, "Server Error: " + resultCode, Toast.LENGTH_LONG).show();
        }
    }
} 

Like I said, this all worked fine until yesterday afternoon. I am using SOAP UI to test on the browser and then building the SOAP message using the StringManipulator class.

The final soap login looks like this:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
    <soapenv:Header/>
    <soapenv:Body>
        <tem:Login>
            <tem:login>username</tem:login>
            <tem:password>password</tem:password>
        </tem:Login>
    </soapenv:Body>
</soapenv:Envelope>

The response status line is:

HTTP/1.1 405 Method Not Allowed

The response body is:

07-16 10:38:01.113: E/result(6877): <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
07-16 10:38:01.113: E/result(6877): <html xmlns="http://www.w3.org/1999/xhtml"> 
07-16 10:38:01.113: E/result(6877): <head> 
07-16 10:38:01.113: E/result(6877): <title>IIS 8.5 Detailed Error - 405.0 - Method Not Allowed</title> 
07-16 10:38:01.113: E/result(6877): <style type="text/css"> 
07-16 10:38:01.113: E/result(6877): <!-- 
07-16 10:38:01.113: E/result(6877): body{margin:0;font-size:.7em;font-family:Verdana,Arial,Helvetica,sans-serif;} 
07-16 10:38:01.113: E/result(6877): code{margin:0;color:#006600;font-size:1.1em;font-weight:bold;} 
07-16 10:38:01.113: E/result(6877): .config_source code{font-size:.8em;color:#000000;} 
07-16 10:38:01.113: E/result(6877): pre{margin:0;font-size:1.4em;word-wrap:break-word;} 
07-16 10:38:01.113: E/result(6877): ul,ol{margin:10px 0 10px 5px;} 
07-16 10:38:01.113: E/result(6877): ul.first,ol.first{margin-top:5px;} 
07-16 10:38:01.113: E/result(6877): fieldset{padding:0 15px 10px 15px;word-break:break-all;} 
07-16 10:38:01.113: E/result(6877): .summary-container fieldset{padding-bottom:5px;margin-top:4px;} 
07-16 10:38:01.113: E/result(6877): legend.no-expand-all{padding:2px 15px 4px 10px;margin:0 0 0 -12px;} 
07-16 10:38:01.113: E/result(6877): legend{color:#333333;;margin:4px 0 8px -12px;_margin-top:0px; 
07-16 10:38:01.113: E/result(6877): font-weight:bold;font-size:1em;} 
07-16 10:38:01.113: E/result(6877): a:link,a:visited{color:#007EFF;font-weight:bold;} 
07-16 10:38:01.113: E/result(6877): a:hover{text-decoration:none;} 
07-16 10:38:01.113: E/result(6877): h1{font-size:2.4em;margin:0;color:#FFF;} 
07-16 10:38:01.113: E/result(6877): h2{font-size:1.7em;margin:0;color:#CC0000;} 
07-16 10:38:01.113: E/result(6877): h3{font-size:1.4em;margin:10px 0 0 0;color:#CC0000;} 
07-16 10:38:01.113: E/result(6877): h4{font-size:1.2em;margin:10px 0 5px 0; 
07-16 10:38:01.113: E/result(6877): }#header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:"trebuchet MS",Verdana,sans-serif; 
07-16 10:38:01.113: E/result(6877):  color:#FFF;background-color:#5C87B2; 
07-16 10:38:01.113: E/result(6877): }#content{margin:0 0 0 2%;position:relative;} 
07-16 10:38:01.113: E/result(6877): .summary-container,.content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;} 
07-16 10:38:01.113: E/result(6877): .content-container p{margin:0 0 10px 0; 
07-16 10:38:01.113: E/result(6877): }#details-left{width:35%;float:left;margin-right:2%; 
07-16 10:38:01.113: E/result(6877): }#details-right{width:63%;float:left;overflow:hidden; 
07-16 10:38:01.113: E/result(6877): }#server_version{width:96%;_height:1px;min-height:1px;margin:0 0 5px 0;padding:11px 2% 8px 2%;color:#FFFFFF; 
07-16 10:38:01.113: E/result(6877):  background-color:#5A7FA5;border-bottom:1px solid #C1CFDD;border-top:1px solid #4A6C8E;font-weight:normal; 
07-16 10:38:01.113: E/result(6877):  font-size:1em;color:#FFF;text-align:right; 
07-16 10:38:01.113: E/result(6877): }#server_version p{margin:5px 0;} 
07-16 10:38:01.113: E/result(6877): table{margin:4px 0 4px 0;width:100%;border:none;} 
07-16 10:38:01.113: E/result(6877): td,th{vertical-align:top;padding:3px 0;text-align:left;font-weight:normal;border:none;} 
07-16 10:38:01.113: E/result(6877): th{width:30%;text-align:right;padding-right:2%;font-weight:bold;} 
07-16 10:38:01.113: E/result(6877): thead th{background-color:#ebebeb;width:25%; 
07-16 10:38:01.113: E/result(6877): }#details-right th{width:20%;} 
07-16 10:38:01.113: E/result(6877): table tr.alt td,table tr.alt th{} 
07-16 10:38:01.113: E/result(6877): .highlight-code{color:#CC0000;font-weight:bold;font-style:italic;} 
07-16 10:38:01.113: E/result(6877): .clear{clear:both;} 
07-16 10:38:01.113: E/result(6877): .preferred{padding:0 5px 2px 5px;font-weight:normal;background:#006633;color:#FFF;font-size:.8em;} 
07-16 10:38:01.113: E/result(6877): --> 
07-16 10:38:01.113: E/result(6877): </style> 
07-16 10:38:01.113: E/result(6877):  
07-16 10:38:01.113: E/result(6877): </head> 
07-16 10:38:01.113: E/result(6877): <body> 
07-16 10:38:01.113: E/result(6877): <div id="content"> 
07-16 10:38:01.113: E/result(6877): <div class="content-container"> 
07-16 10:38:01.113: E/result(6877):   <h3>HTTP Error 405.0 - Method Not Allowed</h3> 
07-16 10:38:01.113: E/result(6877):   <h4>The page you are looking for cannot be displayed because an invalid method (HTTP verb) is being used.</h4> 
07-16 10:38:01.113: E/result(6877): </div> 
07-16 10:38:01.113: E/result(6877): <div class="content-container"> 
07-16 10:38:01.113: E/result(6877):  <fieldset><h4>Most likely causes:</h4> 
07-16 10:38:01.113: E/result(6877):   <ul>  <li>The request sent to the Web server used an HTTP verb that is not allowed by the module configured to handle the request.</li>   <li>A request was sent to the server that contained an invalid HTTP verb.</li>  <li>The request is for static content and contains an HTTP verb other than GET or HEAD.</li>    <li>A request was sent to a virtual directory using the HTTP verb POST and the default document is a static file that does not support HTTP verbs other than GET or HEAD.</li> </ul> 
07-16 10:38:01.113: E/result(6877):  </fieldset> 
07-16 10:38:01.113: E/result(6877): </div> 
07-16 10:38:01.113: E/result(6877): <div class="content-container"> 
07-16 10:38:01.113: E/result(6877):  <fieldset><h4>Things you can try:</h4> 
07-16 10:38:01.113: E/result(6877):   <ul>  <li>Verify the list of verbs enabled for the module handler this request was sent to, and ensure that this verb should be allowed for the Web site.</li>    <li>Check the IIS log file to see which verb is not allowed for the request.</li>   <li>Create a tracing rule to track failed requests for this HTTP status code. For more information about creating a tracing rule for failed requests, click <a href="http://go.microsoft.com/fwlink/?LinkID=66439">here</a>. </li> </ul> 
07-16 10:38:01.113: E/result(6877):  </fieldset> 
07-16 10:38:01.113: E/result(6877): </div> 
07-16 10:38:01.113: E/result(6877):  
07-16 10:38:01.113: E/result(6877): <div class="content-container"> 
07-16 10:38:01.113: E/result(6877):  <fieldset><h4>Detailed Error Information:</h4> 
07-16 10:38:01.113: E/result(6877):   <div id="details-left"> 
07-16 10:38:01.113: E/result(6877):    <table border="0" cellpadding="0" cellspacing="0"> 
07-16 10:38:01.113: E/result(6877):     <tr class="alt"><th>Module</th><td>&nbsp;&nbsp;&nbsp;StaticFileModule</td></tr>

Like I said, this is strange because between yesterday before lunch and yesterday after lunch, I changed nothing... so why would I be getting a new response from the server?

I am at a loss for things to try.

解决方案

If it worked, you went to lunch, came back and it no longer works (and you really didn't change anything, as you say) then somebody else changed something.

You are doing a POST but for some reason IIS does not allow POST for whatever resource you are accessing (maybe a WCF .svc extension?). Seems the "StaticFileModule" is the one complaining based on the error page you get back.

Maybe someone reconfigured the server and now your request is handled by another handler? I suggest you contact your network administrators or site admins and ask them if something was reconfigured, new software installed, updates applied, etc in the time frame when you noticed your method call is no longer functional.

这篇关于Android SOAP 请求返回 HTTP 响应 405的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆