我正在尝试访问Android应用程序上的.net web api项目。这是代码;
public class HttpTask extends AsyncTask<Void, String, String> {
String filename;
String url;
public HttpTask(String filename, String url) {
this.filename = filename;
this.url = url;
}
@Override
protected String doInBackground(Void... voids) {
try {
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://192.168.1.105/Mueasyco/api/AddTrack/");
List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(2);
nameValuePair.add(new BasicNameValuePair("filename", filename));
nameValuePair.add(new BasicNameValuePair("url", url));
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair));
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-Type", "application/json");
HttpResponse response = httpClient.execute(httpPost);
return response.toString();
} catch (Exception e) {
Log.e("log_tag", "HTTP connect error " + e.toString());
return "ERROR";
}
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
Log.i("Result is ....", result);
}
}
但是当与服务器通信时,它会收到错误并且它会收到HTTP 405错误,请求到达服务器,&#34;对http处理程序的异步调用已启动&#34;记录。
请求在Android端不是异步的,请求不会。与此同时,测试API的移动应用程序可以进行海上通信