我在这里看到了几个类似的问题但我的有一个很大的区别。我能够使用我的登录Web客户端Web方法大约9个月,然后昨天下午我开始得到405响应。
以下是我的代码:
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();
}
}
}
像我说的那样,直到昨天下午这一切都很好。我正在使用SOAP UI在浏览器上进行测试,然后使用StringManipulator
类构建SOAP消息。
最终的肥皂登录如下:
<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>
响应状态行为:
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 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> StaticFileModule</td></tr>
就像我说的,这很奇怪,因为昨天午餐前和昨天午餐后,我什么都没改变......所以我为什么要从服务器那里得到新的回复呢?
我不知道要尝试的事情。
答案 0 :(得分:0)
如果它有效,你去吃午饭,回来后它就不再有效了(你真的没有改变任何东西,正如你所说的那样)然后别人改变了一些东西。
您正在进行POST但由于某种原因,IIS不允许对您正在访问的任何资源进行POST(可能是WCF .svc扩展名?)。似乎&#34; StaticFileModule&#34;是基于你回来的错误页面抱怨的人。
也许有人重新配置了服务器,现在你的请求是由另一个处理程序处理的?我建议您联系您的网络管理员或站点管理员,并在您发现方法调用不再起作用的时间范围内询问他们是否重新配置了某些内容,安装了新软件,应用了更新等等。