我的 android 应用会向在我的公共网站上运行的 ASP NET WEB API 服务发送 POST。在 AVD 模拟器上测试时效果很好。但是当我在我的 Android 手机上测试时,我得到...
“连接到http://www.deanblakely.com被拒绝”
我的邮政编码粘贴在下面谢谢,加里
private String PostToCloudService(URL url, String entityString)
{
String retstr = "";
try
{
Log.w(getClass().getName(), "copy this: " + entityString );
Log.w(getClass().getName(), "URL is: " + url );
HttpResponse response = null;
HttpParams myParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(myParams,5000);
HttpConnectionParams.setSoTimeout(myParams, 5000);
HttpClient httpclient = new DefaultHttpClient(myParams);
HttpPost myPost = new HttpPost(url.toString());
StringEntity se = new StringEntity(entityString);
myPost.setEntity(se);
myPost.setHeader("Accept", "application/json");
myPost.setHeader("Content-type", "application/json");
response = httpclient.execute(myPost);
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line = "";
while ((line = rd.readLine()) != null)
{
Log.w(getClass().getName(), "response from getentity is " + line);
retstr = line;
}
}
catch (Exception e)
{
Log.w(getClass().getName(), e.getMessage().toString());
retstr = "error " + e.getMessage().toString();
}
return retstr;
}