Java Android未连接到在浏览器中工作的WCF服务
我有一个WCF服务(在浏览器中尝试了它)它的代码Java Android未连接到在浏览器中工作的WCF服务,java,c#,android,web-services,wcf,Java,C#,Android,Web Services,Wcf,我有一个WCF服务(在浏览器中尝试了它)它的代码 [OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "Login/?username={username}&password={password}")] bool Login(string us
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "Login/?username={username}&password={password}")]
bool Login(string username, string password);
[OperationContract]
[WebGet(UriTemplate = "Search/?query={query}&type={type}", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
List<AndroidBook> Search(string query, int type);
这是正确的,但在尝试使用以下代码连接android客户端时:
try {
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(new HttpGet(urls));
StatusLine statusLine = response.getStatusLine();
if(statusLine.getStatusCode() == HttpStatus.SC_OK){
ByteArrayOutputStream out = new ByteArrayOutputStream();
response.getEntity().writeTo(out);
out.close();
String responseString = out.toString();
//..more logic
} else{
//Closes the connection.
response.getEntity().getContent().close();
throw new IOException(statusLine.getReasonPhrase());
}
} catch (IOException e) {
Log.e("HTTP GET:", e.toString());
}
我遇到了filenotfound
的异常,或者当我收到外部代码的响应时,我收到了一个错误的请求
,我在谷歌上搜索了这个问题,遇到了同样的问题,并阅读了以下文章使用fiddler,我在JSON中得到了正确的响应
任何帮助都将不胜感激:)您是否在android中使用了asynctask或用于网络操作的线程?@IllegalArgument我读到了关于
asynctask
,但出于测试目的,我在android代码StrictMode.ThreadPolicy policy=new StrictMode.ThreadPolicy.Builder().permitAll().build()中添加了以下内容:;StrictMode.setThreadPolicy(策略)你认为这就是我的问题的原因吗?解释一下你的设置。网络服务器?哪里在电脑上?在网上?使用设备或模拟器?我让服务器在本地主机pc上运行,在Windows 8.1上使用VS2013x64@Mhd我有同样的问题,你做和几乎相同的设置的Web服务器,请帮助
{"LoginResult":true}
try {
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(new HttpGet(urls));
StatusLine statusLine = response.getStatusLine();
if(statusLine.getStatusCode() == HttpStatus.SC_OK){
ByteArrayOutputStream out = new ByteArrayOutputStream();
response.getEntity().writeTo(out);
out.close();
String responseString = out.toString();
//..more logic
} else{
//Closes the connection.
response.getEntity().getContent().close();
throw new IOException(statusLine.getReasonPhrase());
}
} catch (IOException e) {
Log.e("HTTP GET:", e.toString());
}