Android 调用post方法
我无法从android应用程序调用post方法 当我从chorome浏览器调用以下url时,它工作正常 我得到了以下回应 请求URL: 申请方式:邮寄 响应时间:6.689秒 响应状态:200-正常 但从安卓系统来看,它不起作用。。我目前的安卓代码是:Android 调用post方法,android,asp.net-web-api,Android,Asp.net Web Api,我无法从android应用程序调用post方法 当我从chorome浏览器调用以下url时,它工作正常 我得到了以下回应 请求URL: 申请方式:邮寄 响应时间:6.689秒 响应状态:200-正常 但从安卓系统来看,它不起作用。。我目前的安卓代码是: String url1= "http://172.16.2.113/api/DigitechProductsAC/PostService"; String data= "ctcCompany=test&name
String url1= "http://172.16.2.113/api/DigitechProductsAC/PostService";
String data= "ctcCompany=test&name=test&mobile=test1&description=test2&address=test3&productCompany=test4&extra1=asdf&extra2=zzz";
String response = "";
try {
URL url = new URL(url1);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
String urlParam = data;
connection.setRequestMethod("POST");
connection.setRequestProperty("USER-AGENT","Mozilla/5.0");
connection.setRequestProperty("ACCEPT-LANGUAGE","en-US,en;0.5");
connection.setDoOutput(true);
DataOutputStream dataOutputStream = new DataOutputStream(connection.getOutputStream());
dataOutputStream.writeBytes(urlParam);
dataOutputStream.flush();
dataOutputStream.close();
int responseCode= connection.getResponseCode();
if (responseCode==200)
return "OK";
else
return "";
}catch (Exception ex)
{
return null;
}
它没有到达服务器 请延伸你的问题。什么东西坏了?它到达服务器了吗?它是否抛出错误?它没有到达服务器1:您是否在
异步任务
中异步运行此代码。2:你调试过这段代码吗,我是说它停在哪里,响应状态代码是什么,响应错误是什么,或者引发了什么异常?